summaryrefslogtreecommitdiffhomepage
path: root/src/python/nxt_python_asgi_str.c
diff options
context:
space:
mode:
authorsynodriver <diguohuangjiajinweijun@gmail.com>2023-05-27 22:18:46 +0800
committerAndrew Clayton <a.clayton@nginx.com>2023-06-01 00:25:03 +0100
commit93ed66958e11b40cc06dcb32fc8e623967af6347 (patch)
tree720ddd839d0594a0ffc6fb36e8c8a71fcd42b2a9 /src/python/nxt_python_asgi_str.c
parent31ff94add9c4043a753683d9e8b68733c69aa1ac (diff)
downloadunit-93ed66958e11b40cc06dcb32fc8e623967af6347.tar.gz
unit-93ed66958e11b40cc06dcb32fc8e623967af6347.tar.bz2
Python: Add ASGI lifespan state support.
Lifespan state is a special dict in asgi lifespan scope, which allow applications to persist data from the lifespan cycle to request/response handling. The scope["state"] namespace provides a place to store these sorts of things. The server will ensure that a shallow copy of the namespace is passed into each subsequent request/response call into the application. Some frameworks are already taking advantage of this feature, for example, starlette, and without this feature they wouldn't work properly. Signed-off-by: synodriver <diguohuangjiajinweijun@gmail.com> Reviewed-by: Andrew Clayton <a.clayton@nginx.com> [ Minor code tweaks to avoid lines > 80 chars, static a function and re-work the PyMemberDef structure initialisation for Python <3.7 and -Wwrite-strings compatibility - Andrew ] Tested-by: <https://github.com/synodriver> Tested-by: <https://github.com/hawiliali> Closes: <https://github.com/nginx/unit/issues/864> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/python/nxt_python_asgi_str.c')
-rw-r--r--src/python/nxt_python_asgi_str.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/python/nxt_python_asgi_str.c b/src/python/nxt_python_asgi_str.c
index 7171d52b..3bea87d5 100644
--- a/src/python/nxt_python_asgi_str.c
+++ b/src/python/nxt_python_asgi_str.c
@@ -55,6 +55,7 @@ PyObject *nxt_py_subprotocol_str;
PyObject *nxt_py_subprotocols_str;
PyObject *nxt_py_text_str;
PyObject *nxt_py_type_str;
+PyObject *nxt_py_state_str;
PyObject *nxt_py_version_str;
PyObject *nxt_py_websocket_str;
PyObject *nxt_py_websocket_accept_str;
@@ -110,6 +111,7 @@ static nxt_python_string_t nxt_py_asgi_strings[] = {
{ nxt_string("subprotocols"), &nxt_py_subprotocols_str },
{ nxt_string("text"), &nxt_py_text_str },
{ nxt_string("type"), &nxt_py_type_str },
+ { nxt_string("state"), &nxt_py_state_str },
{ nxt_string("version"), &nxt_py_version_str },
{ nxt_string("websocket"), &nxt_py_websocket_str },
{ nxt_string("websocket.accept"), &nxt_py_websocket_accept_str },