Files
nginx-unit/test/python/body_bytearray/asgi.py
Andrei Zeliankou 697a585062 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.
2024-02-21 14:06:43 +00:00

21 lines
516 B
Python

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})