summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_python_wsgi.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nxt_python_wsgi.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
index d2eb5d5b..7c24828a 100644
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -773,6 +773,14 @@ nxt_py_start_resp(PyObject *self, PyObject *args)
static const u_char cr_lf[] = "\r\n";
static const u_char sc_sp[] = ": ";
+ ctx = nxt_python_run_ctx;
+
+ if (nxt_slow_path(ctx == NULL)) {
+ return PyErr_Format(PyExc_RuntimeError,
+ "start_response() is called "
+ "outside of WSGI request processing");
+ }
+
n = PyTuple_GET_SIZE(args);
if (n < 2 || n > 3) {
@@ -781,8 +789,6 @@ nxt_py_start_resp(PyObject *self, PyObject *args)
string = PyTuple_GET_ITEM(args, 0);
- ctx = nxt_python_run_ctx;
-
nxt_python_write(ctx, status, sizeof(status) - 1, 0, 0);
rc = nxt_python_write_py_str(ctx, string, 0, 0);
@@ -862,6 +868,12 @@ nxt_py_input_read(nxt_py_input_t *self, PyObject *args)
ctx = nxt_python_run_ctx;
+ if (nxt_slow_path(ctx == NULL)) {
+ return PyErr_Format(PyExc_RuntimeError,
+ "wsgi.input.read() is called "
+ "outside of WSGI request processing");
+ }
+
size = ctx->body_preread_size;
n = PyTuple_GET_SIZE(args);