diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index fbc13f55..0da9b28f 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -4,6 +4,26 @@ extern struct uwsgi_server uwsgi; extern struct uwsgi_python up; extern struct uwsgi_plugin python_plugin; +static PyObject *py_uwsgi_add_var(PyObject * self, PyObject * args) { + char *key = NULL; + Py_ssize_t keylen = 0; + char *val = NULL; + Py_ssize_t vallen = 0; + struct wsgi_request *wsgi_req = py_current_wsgi_req(); + + if (!PyArg_ParseTuple(args, "#s#s", &key, &keylen, &val, &vallen)) { + return NULL; + } + + if (!uwsgi_req_append(wsgi_req, key, keylen, val, vallen)) { + return PyErr_Format(PyExc_ValueError, "unable to add request var, check your buffer size"); + } + + Py_INCREF(Py_True); + return Py_True; +} + + static PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) { struct wsgi_request *wsgi_req = py_current_wsgi_req(); @@ -2417,6 +2437,8 @@ static PyMethodDef uwsgi_advanced_methods[] = { {"ready_fd", py_uwsgi_ready_fd, METH_VARARGS, ""}, + {"add_var", py_uwsgi_add_var, METH_VARARGS, ""}, + {NULL, NULL}, };