Switch to websockets 6.0
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
parent
a87934d434
commit
c578974246
|
@ -15,6 +15,6 @@ dependencies:
|
||||||
- httptools>=0.0.9
|
- httptools>=0.0.9
|
||||||
- ujson>=1.35
|
- ujson>=1.35
|
||||||
- aiofiles>=0.3.0
|
- aiofiles>=0.3.0
|
||||||
- websockets>=3.2
|
- websockets>=6.0
|
||||||
- sphinxcontrib-asyncio>=0.2.0
|
- sphinxcontrib-asyncio>=0.2.0
|
||||||
- https://github.com/channelcat/docutils-fork/zipball/master
|
- https://github.com/channelcat/docutils-fork/zipball/master
|
||||||
|
|
|
@ -2,5 +2,5 @@ aiofiles
|
||||||
httptools
|
httptools
|
||||||
ujson; sys_platform != "win32" and implementation_name == "cpython"
|
ujson; sys_platform != "win32" and implementation_name == "cpython"
|
||||||
uvloop; sys_platform != "win32" and implementation_name == "cpython"
|
uvloop; sys_platform != "win32" and implementation_name == "cpython"
|
||||||
websockets>=5.0,<6.0
|
websockets>=6.0,<7.0
|
||||||
multidict>=4.0,<5.0
|
multidict>=4.0,<5.0
|
||||||
|
|
|
@ -57,17 +57,11 @@ class WebSocketProtocol(HttpProtocol):
|
||||||
|
|
||||||
async def websocket_handshake(self, request, subprotocols=None):
|
async def websocket_handshake(self, request, subprotocols=None):
|
||||||
# let the websockets package do the handshake with the client
|
# let the websockets package do the handshake with the client
|
||||||
headers = []
|
headers = {}
|
||||||
|
|
||||||
def get_header(k):
|
|
||||||
return request.headers.get(k, '')
|
|
||||||
|
|
||||||
def set_header(k, v):
|
|
||||||
headers.append((k, v))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
key = handshake.check_request(get_header)
|
key = handshake.check_request(request.headers)
|
||||||
handshake.build_response(set_header, key)
|
handshake.build_response(headers, key)
|
||||||
except InvalidHandshake:
|
except InvalidHandshake:
|
||||||
raise InvalidUsage('Invalid websocket request')
|
raise InvalidUsage('Invalid websocket request')
|
||||||
|
|
||||||
|
@ -79,12 +73,12 @@ class WebSocketProtocol(HttpProtocol):
|
||||||
for p in client_subprotocols:
|
for p in client_subprotocols:
|
||||||
if p in subprotocols:
|
if p in subprotocols:
|
||||||
subprotocol = p
|
subprotocol = p
|
||||||
set_header('Sec-Websocket-Protocol', subprotocol)
|
headers['Sec-Websocket-Protocol'] = subprotocol
|
||||||
break
|
break
|
||||||
|
|
||||||
# write the 101 response back to the client
|
# write the 101 response back to the client
|
||||||
rv = b'HTTP/1.1 101 Switching Protocols\r\n'
|
rv = b'HTTP/1.1 101 Switching Protocols\r\n'
|
||||||
for k, v in headers:
|
for k, v in headers.items():
|
||||||
rv += k.encode('utf-8') + b': ' + v.encode('utf-8') + b'\r\n'
|
rv += k.encode('utf-8') + b': ' + v.encode('utf-8') + b'\r\n'
|
||||||
rv += b'\r\n'
|
rv += b'\r\n'
|
||||||
request.transport.write(rv)
|
request.transport.write(rv)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -60,7 +60,7 @@ requirements = [
|
||||||
uvloop,
|
uvloop,
|
||||||
ujson,
|
ujson,
|
||||||
'aiofiles>=0.3.0',
|
'aiofiles>=0.3.0',
|
||||||
'websockets>=5.0,<6.0',
|
'websockets>=6.0,<7.0',
|
||||||
'multidict>=4.0,<5.0',
|
'multidict>=4.0,<5.0',
|
||||||
]
|
]
|
||||||
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
|
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user