Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 7016773

Browse files
committed
Change to_host_port_tuple to use regex and update default port
1 parent d6b7ccc commit 7016773

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

hyper/common/util.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
General utility functions for use with hyper.
77
"""
88
from hyper.compat import unicode, bytes, imap
9+
import re
910

1011
def to_bytestring(element):
1112
"""
@@ -31,17 +32,11 @@ def to_host_port_tuple(host_port_str, default_port=80):
3132
Converts the given string containing a host and possibly a port
3233
to a tuple.
3334
"""
34-
if ']' in host_port_str:
35-
delim = ']:'
35+
if re.search("\]:\d+|\.\d{1-3}:\d+|[a-zA-Z0-9-]+:\d+", host_port_str):
36+
host, port = host_port_str.rsplit(':', 1)
37+
port = int(port)
3638
else:
37-
delim = ':'
38-
39-
try:
40-
host, port = host_port_str.rsplit(delim, 1)
41-
except ValueError:
4239
host, port = host_port_str, default_port
43-
else:
44-
port = int(port)
4540

4641
host = host.strip('[]')
4742

hyper/http20/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, host, port=None, secure=None, window_manager=None, enable_pus
6868
Creates an HTTP/2 connection to a specific server.
6969
"""
7070
if port is None:
71-
self.host, self.port = to_host_port_tuple(host)
71+
self.host, self.port = to_host_port_tuple(host, default_port=443)
7272
else:
7373
self.host, self.port = host, port
7474

0 commit comments

Comments
 (0)