From 697a58506235e89af1c8cc3cafc92b3d85a3467d Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Fri, 26 Jan 2024 14:58:43 +0000 Subject: Python: bytearray body support for ASGI module. @filiphanes requested support for bytearray and memoryview in the request body here: This patch implements bytearray body support only. Memoryview body still need to be implemented. --- test/python/body_bytearray/asgi.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/python/body_bytearray/asgi.py (limited to 'test/python/body_bytearray') 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}) -- cgit