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.
This commit is contained in:
committed by
andrey-zelenkov
parent
f71ead5fa5
commit
697a585062
20
test/python/body_bytearray/asgi.py
Normal file
20
test/python/body_bytearray/asgi.py
Normal file
@@ -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})
|
||||
@@ -218,6 +218,14 @@ def test_asgi_application_shm_ack_handle():
|
||||
assert resp['body'] == body, 'keep-alive 1'
|
||||
|
||||
|
||||
def test_asgi_application_body_bytearray():
|
||||
client.load('body_bytearray')
|
||||
|
||||
body = '0123456789'
|
||||
|
||||
assert client.post(body=body)['body'] == body
|
||||
|
||||
|
||||
def test_asgi_keepalive_body():
|
||||
client.load('mirror')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user