File: server.py

package info (click to toggle)
hypercorn 0.17.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 908 kB
  • sloc: python: 7,839; makefile: 24; sh: 6
file content (25 lines) | stat: -rw-r--r-- 808 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
async def app(scope, receive, send):
    while True:
        event = await receive()
        if event['type'] == 'http.disconnect':
            break
        elif event['type'] == 'http.request' and not event.get('more_body', False):
            await send_data(send)
            break
        elif event['type'] == 'lifespan.startup':
            await send({'type': 'lifespan.startup.complete'})
        elif event['type'] == 'lifespan.shutdown':
            await send({'type': 'lifespan.shutdown.complete'})
            break

async def send_data(send):
    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [(b'content-length', b'5')],
    })
    await send({
        'type': 'http.response.body',
        'body': b'Hello',
        'more_body': False,
    })