Merge 36291ba10d into 3dd228b81a
This commit is contained in:
commit
56963373ef
|
|
@ -87,6 +87,20 @@ class AcceptTestCase(unittest.TestCase):
|
||||||
self.assertEqual(sock.data[:13], b'HTTP/1.1 101 ')
|
self.assertEqual(sock.data[:13], b'HTTP/1.1 101 ')
|
||||||
self.assertTrue(b'\r\nSec-WebSocket-Protocol: gazonk\r\n' in sock.data)
|
self.assertTrue(b'\r\nSec-WebSocket-Protocol: gazonk\r\n' in sock.data)
|
||||||
|
|
||||||
|
def test_protocol_with_space_after_comma(self):
|
||||||
|
class ProtoSocket(websocket.WebSocket):
|
||||||
|
def select_subprotocol(self, protocol):
|
||||||
|
return 'gazonk'
|
||||||
|
|
||||||
|
ws = ProtoSocket()
|
||||||
|
sock = FakeSocket()
|
||||||
|
ws.accept(sock, {'upgrade': 'websocket',
|
||||||
|
'Sec-WebSocket-Version': '13',
|
||||||
|
'Sec-WebSocket-Key': 'DKURYVK9cRFul1vOZVA56Q==',
|
||||||
|
'Sec-WebSocket-Protocol': 'foobar, gazonk'})
|
||||||
|
self.assertEqual(sock.data[:13], b'HTTP/1.1 101 ')
|
||||||
|
self.assertTrue(b'\r\nSec-WebSocket-Protocol: gazonk\r\n' in sock.data)
|
||||||
|
|
||||||
def test_no_protocol(self):
|
def test_no_protocol(self):
|
||||||
ws = websocket.WebSocket()
|
ws = websocket.WebSocket()
|
||||||
sock = FakeSocket()
|
sock = FakeSocket()
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,9 @@ class WebSocket:
|
||||||
accept = b64encode(accept).decode("ascii")
|
accept = b64encode(accept).decode("ascii")
|
||||||
|
|
||||||
self.protocol = ''
|
self.protocol = ''
|
||||||
protocols = headers.get('Sec-WebSocket-Protocol', '').split(',')
|
# Tokens may be separated by ", " so strip whitespace per RFC 7230
|
||||||
|
protocols = [p.strip() for p in
|
||||||
|
headers.get('Sec-WebSocket-Protocol', '').split(',')]
|
||||||
if protocols:
|
if protocols:
|
||||||
self.protocol = self.select_subprotocol(protocols)
|
self.protocol = self.select_subprotocol(protocols)
|
||||||
# We are required to choose one of the protocols
|
# We are required to choose one of the protocols
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue