aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/http')
-rw-r--r--netlib/http/http1/assemble.py4
-rw-r--r--netlib/http/url.py15
2 files changed, 16 insertions, 3 deletions
diff --git a/netlib/http/http1/assemble.py b/netlib/http/http1/assemble.py
index 00d1563b..511328f1 100644
--- a/netlib/http/http1/assemble.py
+++ b/netlib/http/http1/assemble.py
@@ -1,6 +1,6 @@
from __future__ import absolute_import, print_function, division
-from netlib import utils
+import netlib.http.url
from netlib import exceptions
@@ -82,7 +82,7 @@ def _assemble_request_headers(request_data):
"""
headers = request_data.headers.copy()
if "host" not in headers and request_data.scheme and request_data.host and request_data.port:
- headers["host"] = utils.hostport(
+ headers["host"] = netlib.http.url.hostport(
request_data.scheme,
request_data.host,
request_data.port
diff --git a/netlib/http/url.py b/netlib/http/url.py
index 5d461387..2fc6e7ee 100644
--- a/netlib/http/url.py
+++ b/netlib/http/url.py
@@ -78,7 +78,7 @@ def unparse(scheme, host, port, path=""):
"""
if path == "*":
path = ""
- return "%s://%s%s" % (scheme, utils.hostport(scheme, host, port), path)
+ return "%s://%s%s" % (scheme, hostport(scheme, host, port), path)
def encode(s):
@@ -94,3 +94,16 @@ def decode(s):
Takes a urlencoded string and returns a list of (key, value) tuples.
"""
return urllib.parse.parse_qsl(s, keep_blank_values=True)
+
+
+def hostport(scheme, host, port):
+ """
+ Returns the host component, with a port specifcation if needed.
+ """
+ if (port, scheme) in [(80, "http"), (443, "https"), (80, b"http"), (443, b"https")]:
+ return host
+ else:
+ if isinstance(host, six.binary_type):
+ return b"%s:%d" % (host, port)
+ else:
+ return "%s:%d" % (host, port)