mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Handle HTTP versions malformed due to non-integer major/minor numbers.
This commit is contained in:
parent
2387d2e8ed
commit
29f907ecf9
@ -145,8 +145,11 @@ def parse_http_protocol(s):
|
||||
if "." not in version:
|
||||
return None
|
||||
major, minor = version.split('.')
|
||||
try:
|
||||
major = int(major)
|
||||
minor = int(minor)
|
||||
except ValueError:
|
||||
return None
|
||||
return major, minor
|
||||
|
||||
|
||||
|
@ -106,6 +106,8 @@ def test_read_http_body():
|
||||
def test_parse_http_protocol():
|
||||
assert http.parse_http_protocol("HTTP/1.1") == (1, 1)
|
||||
assert http.parse_http_protocol("HTTP/0.0") == (0, 0)
|
||||
assert not http.parse_http_protocol("HTTP/a.1")
|
||||
assert not http.parse_http_protocol("HTTP/1.a")
|
||||
assert not http.parse_http_protocol("foo/0.0")
|
||||
assert not http.parse_http_protocol("HTTP/x")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user