Skip to content

Commit

Permalink
refs #357
Browse files Browse the repository at this point in the history
  • Loading branch information
liris committed Dec 10, 2017
1 parent d3b78d1 commit 6bc909b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions websocket/_handshake.py
Expand Up @@ -73,6 +73,12 @@ def handshake(sock, hostname, port, resource, **options):

return handshake_response(status, resp, subproto)

def _pack_hostname(hostname):
# IPv6 address
if ':' in hostname:
return '[' + hostname + ']'

return hostname

def _get_handshake_headers(resource, host, port, options):
headers = [
Expand All @@ -81,9 +87,9 @@ def _get_handshake_headers(resource, host, port, options):
"Connection: Upgrade"
]
if port == 80 or port == 443:
hostport = host
hostport = _pack_hostname(host)
else:
hostport = "%s:%d" % (host, port)
hostport = "%s:%d" % (_pack_hostname(host), port)

if "host" in options and options["host"] is not None:
headers.append("Host: %s" % options["host"])
Expand Down

0 comments on commit 6bc909b

Please sign in to comment.