-
Notifications
You must be signed in to change notification settings - Fork 40
/
sockjs-testsrv.py
55 lines (40 loc) · 1.5 KB
/
sockjs-testsrv.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import logging
from aiohttp import web
import sockjs
from sockjs.transports.eventsource import EventsourceTransport
from sockjs.transports.htmlfile import HTMLFileTransport
from sockjs.transports.xhrstreaming import XHRStreamingTransport
async def echo_session(manager, session, msg):
if msg.type == sockjs.MsgType.MESSAGE:
session.send(msg.data)
async def close_session_handler(manager, session, msg):
if msg.type == sockjs.MsgType.OPEN:
session.close()
async def broadcast_session(manager, session, msg):
if msg.type == sockjs.MsgType.OPEN:
manager.broadcast(msg.data)
if __name__ == '__main__':
""" Sockjs tests server """
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s')
HTMLFileTransport.maxsize = 4096
EventsourceTransport.maxsize = 4096
XHRStreamingTransport.maxsize = 4096
app = web.Application()
sockjs.add_endpoint(
app, echo_session, name='echo', prefix='/echo'
)
sockjs.add_endpoint(
app, close_session_handler, name='close', prefix='/close'
)
sockjs.add_endpoint(
app, broadcast_session, name='broadcast', prefix='/broadcast'
)
sockjs.add_endpoint(
app, echo_session, name='wsoff', prefix='/disabled_websocket_echo',
disable_transports=('websocket',))
sockjs.add_endpoint(
app, echo_session, name='cookie', prefix='/cookie_needed_echo',
cookie_needed=True
)
web.run_app(app, port=8081)