summaryrefslogtreecommitdiffhomepage
path: root/test/python/body_bytearray/asgi.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2024-01-26 14:58:43 +0000
committerandrey-zelenkov <xim.andrew@gmail.com>2024-02-21 14:06:43 +0000
commit697a58506235e89af1c8cc3cafc92b3d85a3467d (patch)
tree67d8cf28089e947ed59d00c24df934a8a9eea956 /test/python/body_bytearray/asgi.py
parentf71ead5fa5b8bae378a0eca2bedb689cf08a8eff (diff)
downloadunit-697a58506235e89af1c8cc3cafc92b3d85a3467d.tar.gz
unit-697a58506235e89af1c8cc3cafc92b3d85a3467d.tar.bz2
Python: bytearray body support for ASGI module.
@filiphanes requested support for bytearray and memoryview in the request body here: <https://github.com/nginx/unit/issues/648> This patch implements bytearray body support only. Memoryview body still need to be implemented.
Diffstat (limited to 'test/python/body_bytearray/asgi.py')
-rw-r--r--test/python/body_bytearray/asgi.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/python/body_bytearray/asgi.py b/test/python/body_bytearray/asgi.py
new file mode 100644
index 00000000..6d2f402f
--- /dev/null
+++ b/test/python/body_bytearray/asgi.py
@@ -0,0 +1,20 @@
+async def application(scope, receive, send):
+ assert scope['type'] == 'http'
+
+ body = b''
+ while True:
+ m = await receive()
+ body += m.get('body', b'')
+ if not m.get('more_body', False):
+ body = bytearray(body)
+ break
+
+ await send(
+ {
+ 'type': 'http.response.start',
+ 'status': 200,
+ 'headers': [(b'content-length', str(len(body)).encode())],
+ }
+ )
+
+ await send({'type': 'http.response.body', 'body': body})