aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/utils.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-26 00:39:04 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-26 00:39:04 +0200
commit106f7046d3862cb0e3cbb4f38335af0330b4e7e3 (patch)
tree6a57a7c29062cad851d0b162a17e460b32ea3262 /netlib/utils.py
parent45f2ea33b2fdb67ca89e7eedd860ebe683770497 (diff)
downloadmitmproxy-106f7046d3862cb0e3cbb4f38335af0330b4e7e3.tar.gz
mitmproxy-106f7046d3862cb0e3cbb4f38335af0330b4e7e3.tar.bz2
mitmproxy-106f7046d3862cb0e3cbb4f38335af0330b4e7e3.zip
refactor request model
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 6f6d1ea0..3ec60890 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -273,22 +273,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):