xref: /unit/test/python/mirror/asgi.py (revision 1626:d20f04158166)
1async def application(scope, receive, send):
2    assert scope['type'] == 'http'
3
4    body = b''
5    while True:
6        m = await receive()
7        body += m.get('body', b'')
8        if not m.get('more_body', False):
9            break
10
11    await send({
12        'type': 'http.response.start',
13        'status': 200,
14        'headers': [
15            (b'content-length', str(len(body)).encode()),
16        ]
17    })
18
19    await send({
20        'type': 'http.response.body',
21        'body': body,
22    })
23