xref: /unit/test/python/targets/asgi.py (revision 2273:a13c26f62477)
1async def application_201(scope, receive, send):
2    assert scope['type'] == 'http'
3
4    await send(
5        {
6            'type': 'http.response.start',
7            'status': 201,
8            'headers': [(b'content-length', b'0')],
9        }
10    )
11
12
13async def application_200(scope, receive, send):
14    assert scope['type'] == 'http'
15
16    await send(
17        {
18            'type': 'http.response.start',
19            'status': 200,
20            'headers': [(b'content-length', b'0')],
21        }
22    )
23
24
25async def application_prefix(scope, receive, send):
26    assert scope['type'] == 'http'
27
28    await send(
29        {
30            'type': 'http.response.start',
31            'status': 200,
32            'headers': [
33                (b'content-length', b'0'),
34                (b'prefix', scope.get('root_path', 'NULL').encode()),
35            ],
36        }
37    )
38
39    await send({'type': 'http.response.body', 'body': b''})
40
41
42def legacy_application_200(scope):
43    assert scope['type'] == 'http'
44
45    return legacy_app_http_200
46
47
48async def legacy_app_http_200(receive, send):
49    await send(
50        {
51            'type': 'http.response.start',
52            'status': 200,
53            'headers': [(b'content-length', b'0')],
54        }
55    )
56
57
58def legacy_application_201(scope, receive=None, send=None):
59    assert scope['type'] == 'http'
60
61    return legacy_app_http_201
62
63
64async def legacy_app_http_201(receive, send):
65    await send(
66        {
67            'type': 'http.response.start',
68            'status': 201,
69            'headers': [(b'content-length', b'0')],
70        }
71    )
72