aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/utils.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-28 13:53:59 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-28 13:53:59 +0200
commit67229fbdf7be2f3bb591a9da77f75c05ed0ab269 (patch)
treeaa94ff2eacbe2c5d46dbad3f41c9ca2eae849f73 /netlib/utils.py
parent5261bcdf4b0976b8db3295292143282b34f10c51 (diff)
parent23d13e4c1282bc46c54222479c3b83032dad3335 (diff)
downloadmitmproxy-67229fbdf7be2f3bb591a9da77f75c05ed0ab269.tar.gz
mitmproxy-67229fbdf7be2f3bb591a9da77f75c05ed0ab269.tar.bz2
mitmproxy-67229fbdf7be2f3bb591a9da77f75c05ed0ab269.zip
Merge branch 'http-models'
Diffstat (limited to 'netlib/utils.py')
-rw-r--r--netlib/utils.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/netlib/utils.py b/netlib/utils.py
index 8b9548ed..acc7ccd4 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -274,22 +274,27 @@ def get_header_tokens(headers, key):
return [token.strip() for token in tokens]
-@always_byte_args()
def hostport(scheme, host, port):
"""
Returns the host component, with a port specifcation if needed.
"""
- if (port, scheme) in [(80, b"http"), (443, b"https")]:
+ if (port, scheme) in [(80, "http"), (443, "https"), (80, b"http"), (443, b"https")]:
return host
else:
- return b"%s:%d" % (host, port)
+ if isinstance(host, six.binary_type):
+ return b"%s:%d" % (host, port)
+ else:
+ return "%s:%d" % (host, port)
def unparse_url(scheme, host, port, path=""):
"""
- Returns a URL string, constructed from the specified compnents.
+ Returns a URL string, constructed from the specified components.
+
+ Args:
+ All args must be str.
"""
- return b"%s://%s%s" % (scheme, hostport(scheme, host, port), path)
+ return "%s://%s%s" % (scheme, hostport(scheme, host, port), path)
def urlencode(s):