summaryrefslogtreecommitdiffhomepage
path: root/src/python/nxt_python_asgi_http.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-11-18 22:33:53 +0300
committerMax Romanov <max.romanov@nginx.com>2020-11-18 22:33:53 +0300
commit25219a7ece30a5b21ac0674c557137f91b4b47fe (patch)
tree94d692f2e224ca6bb69249c7c7c8cc5f77360058 /src/python/nxt_python_asgi_http.c
parent66bb41e8bbe81d82a66f0d7188ad89963b4cd251 (diff)
downloadunit-25219a7ece30a5b21ac0674c557137f91b4b47fe.tar.gz
unit-25219a7ece30a5b21ac0674c557137f91b4b47fe.tar.bz2
Python: improving ASGI http send message processing.
Diffstat (limited to 'src/python/nxt_python_asgi_http.c')
-rw-r--r--src/python/nxt_python_asgi_http.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/python/nxt_python_asgi_http.c b/src/python/nxt_python_asgi_http.c
index 5ea8e0a5..d88c4b00 100644
--- a/src/python/nxt_python_asgi_http.c
+++ b/src/python/nxt_python_asgi_http.c
@@ -262,22 +262,23 @@ nxt_py_asgi_http_send(PyObject *self, PyObject *dict)
nxt_unit_req_debug(http->req, "asgi_http_send type is '%.*s'",
(int) type_len, type_str);
- if (type_len == (Py_ssize_t) response_start.length
- && memcmp(type_str, response_start.start, type_len) == 0)
- {
- return nxt_py_asgi_http_response_start(http, dict);
- }
+ if (nxt_unit_response_is_init(http->req)) {
+ if (nxt_str_eq(&response_body, type_str, (size_t) type_len)) {
+ return nxt_py_asgi_http_response_body(http, dict);
+ }
- if (type_len == (Py_ssize_t) response_body.length
- && memcmp(type_str, response_body.start, type_len) == 0)
- {
- return nxt_py_asgi_http_response_body(http, dict);
+ return PyErr_Format(PyExc_RuntimeError,
+ "Expected ASGI message 'http.response.body', "
+ "but got '%U'", type);
}
- nxt_unit_req_error(http->req, "asgi_http_send: unexpected 'type': '%.*s'",
- (int) type_len, type_str);
+ if (nxt_str_eq(&response_start, type_str, (size_t) type_len)) {
+ return nxt_py_asgi_http_response_start(http, dict);
+ }
- return PyErr_Format(PyExc_AssertionError, "unexpected 'type': '%U'", type);
+ return PyErr_Format(PyExc_RuntimeError,
+ "Expected ASGI message 'http.response.start', "
+ "but got '%U'", type);
}