Skip to content

Commit 854b33b

Browse files
author
Mark Edington
committed
Rudimentary fix and testcase for Issue Lawouach#179
Per RFC-6455 protocols and extensions values can contain multiple values and may occur multiple times in the header. This fix handles only the case of the ',' delimiter and not ';'. Enhanced existing test to verify the most basic of parsing examples.
1 parent f84dd25 commit 854b33b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

test/test_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def test_connect_and_close(self, sock):
120120
b"Sec-Websocket-Version: 13",
121121
b"Content-Type: text/plain;charset=utf-8",
122122
b"Sec-Websocket-Accept: " + b64encode(sha1(c.key + WS_KEY).digest()),
123+
b"Sec-WebSocket-Protocol: proto1, proto2",
124+
b"Sec-WebSocket-Extensions: ext1, ext2",
125+
b"Sec-WebSocket-Extensions: ext3",
123126
b"Upgrade: websocket",
124127
b"Date: Sun, 26 Jul 2015 12:32:55 GMT",
125128
b"Server: ws4py/test",
@@ -128,6 +131,8 @@ def test_connect_and_close(self, sock):
128131

129132
c.connect()
130133
s.connect.assert_called_once_with(("127.0.0.1", 80))
134+
self.assertEqual(c.protocols, [b'proto1', b'proto2'])
135+
self.assertEqual(c.extensions, [b'ext1', b'ext2', b'ext3'])
131136

132137
s.reset_mock()
133138
c.close(code=1006, reason="boom")
@@ -273,7 +278,6 @@ def test_thread_is_started_once_connected_secure(self):
273278
self.assertFalse(self.client._th.is_alive())
274279

275280

276-
277281
if __name__ == '__main__':
278282
suite = unittest.TestSuite()
279283
loader = unittest.TestLoader()

ws4py/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ def process_handshake_header(self, headers):
333333
raise HandshakeError("Invalid challenge response: %s" % value)
334334

335335
elif header == b'sec-websocket-protocol':
336-
protocols = ','.join(value)
336+
protocols.extend([x.strip() for x in value.split(b',')])
337337

338338
elif header == b'sec-websocket-extensions':
339-
extensions = ','.join(value)
339+
extensions.extend([x.strip() for x in value.split(b',')])
340340

341341
return protocols, extensions
342342

0 commit comments

Comments
 (0)