aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--netlib/http/http1/read.py5
-rw-r--r--netlib/http/request.py2
-rw-r--r--netlib/utils.py5
-rw-r--r--test/http/http1/test_read.py8
4 files changed, 8 insertions, 12 deletions
diff --git a/netlib/http/http1/read.py b/netlib/http/http1/read.py
index 0d5e7f4b..0f6de26c 100644
--- a/netlib/http/http1/read.py
+++ b/netlib/http/http1/read.py
@@ -218,11 +218,6 @@ def _get_first_line(rfile):
raise HttpReadDisconnect("Remote disconnected")
if not line:
raise HttpReadDisconnect("Remote disconnected")
- line = line.strip()
- try:
- line.decode("ascii")
- except ValueError:
- raise HttpSyntaxException("Non-ascii characters in first line: {}".format(line))
return line.strip()
diff --git a/netlib/http/request.py b/netlib/http/request.py
index 095b5945..92d99532 100644
--- a/netlib/http/request.py
+++ b/netlib/http/request.py
@@ -69,7 +69,7 @@ class Request(Message):
"""
HTTP request method, e.g. "GET".
"""
- return _native(self.data.method)
+ return _native(self.data.method).upper()
@method.setter
def method(self, method):
diff --git a/netlib/utils.py b/netlib/utils.py
index 3ec60890..acc7ccd4 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -237,8 +237,9 @@ def parse_url(url):
if isinstance(url, six.binary_type):
host = parsed.hostname
- # this should not raise a ValueError
- decode_parse_result(parsed, "ascii")
+ # this should not raise a ValueError,
+ # but we try to be very forgiving here and accept just everything.
+ # decode_parse_result(parsed, "ascii")
else:
host = parsed.hostname.encode("idna")
parsed = encode_parse_result(parsed, "ascii")
diff --git a/test/http/http1/test_read.py b/test/http/http1/test_read.py
index 84a43f8b..45f61b4f 100644
--- a/test/http/http1/test_read.py
+++ b/test/http/http1/test_read.py
@@ -182,10 +182,6 @@ def test_get_first_line():
rfile.readline.side_effect = TcpDisconnect
_get_first_line(rfile)
- with raises(HttpSyntaxException):
- rfile = BytesIO(b"GET /\xff HTTP/1.1")
- _get_first_line(rfile)
-
def test_read_request_line():
def t(b):
@@ -225,6 +221,10 @@ def test_read_response_line():
assert t(b"HTTP/1.1 200 OK") == (b"HTTP/1.1", 200, b"OK")
assert t(b"HTTP/1.1 200") == (b"HTTP/1.1", 200, b"")
+
+ # https://github.com/mitmproxy/mitmproxy/issues/784
+ assert t(b"HTTP/1.1 200 Non-Autoris\xc3\xa9") == (b"HTTP/1.1", 200, b"Non-Autoris\xc3\xa9")
+
with raises(HttpSyntaxException):
assert t(b"HTTP/1.1")