* 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
This commit is contained in:
Daniel Baskal 2021-02-14 20:19:00 +03:00 committed by GitHub
parent 9763c1810d
commit aebc40c408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -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)

View File

@ -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")