nxt_python_asgi_http.c (1715:95874fd97501) nxt_python_asgi_http.c (1717:fcd578736562)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6
7#include <python/nxt_python.h>
8

--- 248 unchanged lines hidden (view full) ---

257 return PyErr_Format(PyExc_TypeError, "'type' is not a unicode string");
258 }
259
260 type_str = PyUnicode_AsUTF8AndSize(type, &type_len);
261
262 nxt_unit_req_debug(http->req, "asgi_http_send type is '%.*s'",
263 (int) type_len, type_str);
264
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6
7#include <python/nxt_python.h>
8

--- 248 unchanged lines hidden (view full) ---

257 return PyErr_Format(PyExc_TypeError, "'type' is not a unicode string");
258 }
259
260 type_str = PyUnicode_AsUTF8AndSize(type, &type_len);
261
262 nxt_unit_req_debug(http->req, "asgi_http_send type is '%.*s'",
263 (int) type_len, type_str);
264
265 if (type_len == (Py_ssize_t) response_start.length
266 && memcmp(type_str, response_start.start, type_len) == 0)
267 {
268 return nxt_py_asgi_http_response_start(http, dict);
265 if (nxt_unit_response_is_init(http->req)) {
266 if (nxt_str_eq(&response_body, type_str, (size_t) type_len)) {
267 return nxt_py_asgi_http_response_body(http, dict);
268 }
269
270 return PyErr_Format(PyExc_RuntimeError,
271 "Expected ASGI message 'http.response.body', "
272 "but got '%U'", type);
269 }
270
273 }
274
271 if (type_len == (Py_ssize_t) response_body.length
272 && memcmp(type_str, response_body.start, type_len) == 0)
273 {
274 return nxt_py_asgi_http_response_body(http, dict);
275 if (nxt_str_eq(&response_start, type_str, (size_t) type_len)) {
276 return nxt_py_asgi_http_response_start(http, dict);
275 }
276
277 }
278
277 nxt_unit_req_error(http->req, "asgi_http_send: unexpected 'type': '%.*s'",
278 (int) type_len, type_str);
279
280 return PyErr_Format(PyExc_AssertionError, "unexpected 'type': '%U'", type);
279 return PyErr_Format(PyExc_RuntimeError,
280 "Expected ASGI message 'http.response.start', "
281 "but got '%U'", type);
281}
282
283
284static PyObject *
285nxt_py_asgi_http_response_start(nxt_py_asgi_http_t *http, PyObject *dict)
286{
287 int rc;
288 PyObject *status, *headers, *res;

--- 361 unchanged lines hidden ---
282}
283
284
285static PyObject *
286nxt_py_asgi_http_response_start(nxt_py_asgi_http_t *http, PyObject *dict)
287{
288 int rc;
289 PyObject *status, *headers, *res;

--- 361 unchanged lines hidden ---