Skip to content

Commit

Permalink
Rudimentary fix and testcase for Issue Lawouach#179
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mark Edington committed May 25, 2017
1 parent f84dd25 commit 854b33b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def test_connect_and_close(self, sock):
b"Sec-Websocket-Version: 13",
b"Content-Type: text/plain;charset=utf-8",
b"Sec-Websocket-Accept: " + b64encode(sha1(c.key + WS_KEY).digest()),
b"Sec-WebSocket-Protocol: proto1, proto2",
b"Sec-WebSocket-Extensions: ext1, ext2",
b"Sec-WebSocket-Extensions: ext3",
b"Upgrade: websocket",
b"Date: Sun, 26 Jul 2015 12:32:55 GMT",
b"Server: ws4py/test",
Expand All @@ -128,6 +131,8 @@ def test_connect_and_close(self, sock):

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

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



if __name__ == '__main__':
suite = unittest.TestSuite()
loader = unittest.TestLoader()
Expand Down
4 changes: 2 additions & 2 deletions ws4py/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ def process_handshake_header(self, headers):
raise HandshakeError("Invalid challenge response: %s" % value)

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

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

return protocols, extensions

Expand Down

0 comments on commit 854b33b

Please sign in to comment.