Skip to content

Commit 1b0e6b3

Browse files
committed
Add unit test for passing host to in headers
1 parent 37c8ec5 commit 1b0e6b3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

test/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ def test_parse_wss_scheme_with_query_string(self):
104104
self.assertEqual(c.resource, "/?token=value")
105105
self.assertEqual(c.bind_addr, ("127.0.0.1", 443))
106106

107+
def test_overriding_host_from_headers(self):
108+
c = WebSocketBaseClient(url="wss://127.0.0.1", headers=[("Host", "example123.com")])
109+
self.assertEqual(c.host, "127.0.0.1")
110+
self.assertEqual(c.port, 443)
111+
self.assertEqual(c.bind_addr, ("127.0.0.1", 443))
112+
for h in c.handshake_headers:
113+
if h[0].lower() == "host":
114+
self.assertEqual(h[1], "example123.com")
115+
107116
@patch('ws4py.client.socket')
108117
def test_connect_and_close(self, sock):
109118

ws4py/client/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def handshake_headers(self):
265265
if self.extra_headers:
266266
headers.extend(self.extra_headers)
267267

268+
# keep old logic if no overriding Host in headers
268269
if not any(x for x in headers if x[0].lower() == 'host') and \
269270
'host' not in self.exclude_headers:
270271
headers.append(('Host', '%s:%s' % (self.host, self.port)))

0 commit comments

Comments
 (0)