aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-22 01:56:09 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-22 01:56:09 +0200
commitc7b83225001505b32905376703ec7ddaf200af44 (patch)
treedc998c7ea6b141b239a9047385fd440b506e1b80 /netlib
parentf93752277395d201fabefed8fae6d412f13da699 (diff)
downloadmitmproxy-c7b83225001505b32905376703ec7ddaf200af44.tar.gz
mitmproxy-c7b83225001505b32905376703ec7ddaf200af44.tar.bz2
mitmproxy-c7b83225001505b32905376703ec7ddaf200af44.zip
also accept bytes as arguments
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http/headers.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/netlib/http/headers.py b/netlib/http/headers.py
index 1511ea2d..613beb4f 100644
--- a/netlib/http/headers.py
+++ b/netlib/http/headers.py
@@ -14,16 +14,16 @@ except ImportError: # Workaround for Python < 3.3
import six
-from netlib.utils import always_byte_args
+from netlib.utils import always_byte_args, always_bytes
if six.PY2:
_native = lambda x: x
- _asbytes = lambda x: x
+ _always_bytes = lambda x: x
_always_byte_args = lambda x: x
else:
# While headers _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded.
_native = lambda x: x.decode("utf-8", "surrogateescape")
- _asbytes = lambda x: x.encode("utf-8", "surrogateescape")
+ _always_bytes = lambda x: always_bytes(x, "utf-8", "surrogateescape")
_always_byte_args = always_byte_args("utf-8", "surrogateescape")
@@ -95,9 +95,9 @@ class Headers(MutableMapping, object):
# content_type -> content-type
headers = {
- _asbytes(name).replace(b"_", b"-"): value
+ _always_bytes(name).replace(b"_", b"-"): value
for name, value in six.iteritems(headers)
- }
+ }
self.update(headers)
def __bytes__(self):
@@ -183,7 +183,7 @@ class Headers(MutableMapping, object):
Explicitly set multiple headers for the given key.
See: :py:meth:`get_all`
"""
- values = map(_asbytes, values) # _always_byte_args does not fix lists
+ values = map(_always_bytes, values) # _always_byte_args does not fix lists
if name in self:
del self[name]
self.fields.extend(