aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-01-06 00:11:07 +0100
committerMaximilian Hils <git@maximilianhils.com>2017-01-07 23:08:50 +0100
commitaf194918cf862294216e67555b2a5e4ab9f93b08 (patch)
treedc6d75b17330fe7659df58f496dd0007c92edbbb
parent1e89a938016a8ec446c9c15885bfa3c570b9978d (diff)
downloadmitmproxy-af194918cf862294216e67555b2a5e4ab9f93b08.tar.gz
mitmproxy-af194918cf862294216e67555b2a5e4ab9f93b08.tar.bz2
mitmproxy-af194918cf862294216e67555b2a5e4ab9f93b08.zip
fix HTTP reason phrase encoding
While not explicitly spelled out in the RFCs, the reason phrase is expected to be ISO-8859-1.
-rw-r--r--mitmproxy/net/http/response.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/mitmproxy/net/http/response.py b/mitmproxy/net/http/response.py
index b458a3d8..53c9c1ca 100644
--- a/mitmproxy/net/http/response.py
+++ b/mitmproxy/net/http/response.py
@@ -6,6 +6,7 @@ from mitmproxy.net.http import cookies
from mitmproxy.net.http import headers as nheaders
from mitmproxy.net.http import message
from mitmproxy.net.http import status_codes
+from mitmproxy.utils import strutils
from typing import AnyStr
from typing import Dict
from typing import Iterable
@@ -121,11 +122,12 @@ class Response(message.Message):
HTTP Reason Phrase, e.g. "Not Found".
This is always :py:obj:`None` for HTTP2 requests, because HTTP2 responses do not contain a reason phrase.
"""
- return message._native(self.data.reason)
+ # Encoding: http://stackoverflow.com/a/16674906/934719
+ return self.data.reason.decode("ISO-8859-1", "surrogateescape")
@reason.setter
def reason(self, reason):
- self.data.reason = message._always_bytes(reason)
+ self.data.reason = strutils.always_bytes(reason, "ISO-8859-1", "surrogateescape")
@property
def cookies(self) -> multidict.MultiDictView: