forked from mirrors/kore
Expose get/post params via req.argument for python.
This commit is contained in:
parent
1db3cd96d8
commit
dcb5fd842f
|
@ -65,6 +65,7 @@ struct pyhttp_request {
|
|||
static void pyhttp_dealloc(struct pyhttp_request *);
|
||||
|
||||
static PyObject *pyhttp_response(struct pyhttp_request *, PyObject *);
|
||||
static PyObject *pyhttp_argument(struct pyhttp_request *, PyObject *);
|
||||
static PyObject *pyhttp_body_read(struct pyhttp_request *, PyObject *);
|
||||
static PyObject *pyhttp_populate_get(struct pyhttp_request *, PyObject *);
|
||||
static PyObject *pyhttp_populate_post(struct pyhttp_request *, PyObject *);
|
||||
|
@ -73,6 +74,7 @@ static PyObject *pyhttp_response_header(struct pyhttp_request *, PyObject *);
|
|||
|
||||
static PyMethodDef pyhttp_request_methods[] = {
|
||||
METHOD("response", pyhttp_response, METH_VARARGS),
|
||||
METHOD("argument", pyhttp_argument, METH_VARARGS),
|
||||
METHOD("body_read", pyhttp_body_read, METH_VARARGS),
|
||||
METHOD("populate_get", pyhttp_populate_get, METH_NOARGS),
|
||||
METHOD("populate_post", pyhttp_populate_post, METH_NOARGS),
|
||||
|
|
22
src/python.c
22
src/python.c
|
@ -657,6 +657,28 @@ pyhttp_populate_post(struct pyhttp_request *pyreq, PyObject *args)
|
|||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
pyhttp_argument(struct pyhttp_request *pyreq, PyObject *args)
|
||||
{
|
||||
const char *name;
|
||||
PyObject *value;
|
||||
char *string;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &name)) {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid parameters");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (!http_argument_get_string(pyreq->req, name, &string)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
if ((value = PyUnicode_FromString(string)) == NULL)
|
||||
return (PyErr_NoMemory());
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
pyhttp_get_host(struct pyhttp_request *pyreq, void *closure)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue