diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-09-22 01:48:35 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-09-22 01:48:35 +0200 |
commit | f93752277395d201fabefed8fae6d412f13da699 (patch) | |
tree | 7f3b217b89b7d6b78725ea1a6d0185b13ab2876a /netlib/utils.py | |
parent | 9fbeac50ce3f6ae49b0f0270c508b6e81a1eaf17 (diff) | |
download | mitmproxy-f93752277395d201fabefed8fae6d412f13da699.tar.gz mitmproxy-f93752277395d201fabefed8fae6d412f13da699.tar.bz2 mitmproxy-f93752277395d201fabefed8fae6d412f13da699.zip |
Headers: return str on all Python versions
Diffstat (limited to 'netlib/utils.py')
-rw-r--r-- | netlib/utils.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/netlib/utils.py b/netlib/utils.py index b9848038..d5b30128 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -269,7 +269,7 @@ def get_header_tokens(headers, key): """ if key not in headers: return [] - tokens = headers[key].split(b",") + tokens = headers[key].split(",") return [token.strip() for token in tokens] @@ -320,14 +320,14 @@ def parse_content_type(c): ("text", "html", {"charset": "UTF-8"}) """ - parts = c.split(b";", 1) - ts = parts[0].split(b"/", 1) + parts = c.split(";", 1) + ts = parts[0].split("/", 1) if len(ts) != 2: return None d = {} if len(parts) == 2: - for i in parts[1].split(b";"): - clause = i.split(b"=", 1) + for i in parts[1].split(";"): + clause = i.split("=", 1) if len(clause) == 2: d[clause[0].strip()] = clause[1].strip() return ts[0].lower(), ts[1].lower(), d @@ -337,13 +337,14 @@ def multipartdecode(headers, content): """ Takes a multipart boundary encoded string and returns list of (key, value) tuples. """ - v = headers.get(b"Content-Type") + v = headers.get("Content-Type") if v: v = parse_content_type(v) if not v: return [] - boundary = v[2].get(b"boundary") - if not boundary: + try: + boundary = v[2]["boundary"].encode("ascii") + except (KeyError, UnicodeError): return [] rx = re.compile(br'\bname="([^"]+)"') |