xref: /unit/test/python/websockets/mirror/asgi.py (revision 1848:4bd548074e2c)
11625Smax.romanov@nginx.comasync def application(scope, receive, send):
21625Smax.romanov@nginx.com    if scope['type'] == 'websocket':
31625Smax.romanov@nginx.com        while True:
41625Smax.romanov@nginx.com            m = await receive()
51625Smax.romanov@nginx.com            if m['type'] == 'websocket.connect':
6*1848Szelenkov@nginx.com                await send({'type': 'websocket.accept'})
71625Smax.romanov@nginx.com
81625Smax.romanov@nginx.com            if m['type'] == 'websocket.receive':
9*1848Szelenkov@nginx.com                await send(
10*1848Szelenkov@nginx.com                    {
11*1848Szelenkov@nginx.com                        'type': 'websocket.send',
12*1848Szelenkov@nginx.com                        'bytes': m.get('bytes', None),
13*1848Szelenkov@nginx.com                        'text': m.get('text', None),
14*1848Szelenkov@nginx.com                    }
15*1848Szelenkov@nginx.com                )
161625Smax.romanov@nginx.com
171625Smax.romanov@nginx.com            if m['type'] == 'websocket.disconnect':
18*1848Szelenkov@nginx.com                break
19