From aebc40c408730e6e6113bf364d6f741dfda00740 Mon Sep 17 00:00:00 2001 From: Daniel Baskal <20339505+dlbas@users.noreply.github.com> Date: Sun, 14 Feb 2021 20:19:00 +0300 Subject: [PATCH] Fixes #4416 (#4446) * Fixes #4416 Fix ValueError when splitting on a request URI without a path part. * Fix mypy lintining issue * Replace .split() with .partition() for cleaner code --- mitmproxy/net/http/http1/read.py | 2 +- test/mitmproxy/net/http/http1/test_read.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mitmproxy/net/http/http1/read.py b/mitmproxy/net/http/http1/read.py index 5c75ddd86..b0436e42a 100644 --- a/mitmproxy/net/http/http1/read.py +++ b/mitmproxy/net/http/http1/read.py @@ -111,7 +111,7 @@ def _read_request_line(line: bytes) -> Tuple[str, int, bytes, bytes, bytes, byte raise ValueError else: scheme, rest = target.split(b"://", maxsplit=1) - authority, path_ = rest.split(b"/", maxsplit=1) + authority, _, path_ = rest.partition(b"/") path = b"/" + path_ host, port = url.parse_authority(authority, check=True) port = port or url.default_port(scheme) diff --git a/test/mitmproxy/net/http/http1/test_read.py b/test/mitmproxy/net/http/http1/test_read.py index eef997fc4..cdcc8ef33 100644 --- a/test/mitmproxy/net/http/http1/test_read.py +++ b/test/mitmproxy/net/http/http1/test_read.py @@ -137,6 +137,8 @@ def test_read_request_line(): ("foo", 42, b"CONNECT", b"", b"foo:42", b"", b"HTTP/1.1")) assert (t(b"GET http://foo:42/bar HTTP/1.1") == ("foo", 42, b"GET", b"http", b"foo:42", b"/bar", b"HTTP/1.1")) + assert (t(b"GET http://foo:42 HTTP/1.1") == + ("foo", 42, b"GET", b"http", b"foo:42", b"/", b"HTTP/1.1")) with pytest.raises(ValueError): t(b"GET / WTF/1.1")