diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-07-21 17:27:23 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-07-21 17:27:23 +1200 |
commit | 29f907ecf98468a89b5a7575b539938dc6741a8e (patch) | |
tree | 1725a5821666b886b215d96b364b5582ea3a8a99 | |
parent | 2387d2e8ed7d94e42b1ac02a4ea73f54e4c63ab8 (diff) | |
download | mitmproxy-29f907ecf98468a89b5a7575b539938dc6741a8e.tar.gz mitmproxy-29f907ecf98468a89b5a7575b539938dc6741a8e.tar.bz2 mitmproxy-29f907ecf98468a89b5a7575b539938dc6741a8e.zip |
Handle HTTP versions malformed due to non-integer major/minor numbers.
-rw-r--r-- | netlib/http.py | 7 | ||||
-rw-r--r-- | test/test_http.py | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/netlib/http.py b/netlib/http.py index acd9d85e..88e66ce4 100644 --- a/netlib/http.py +++ b/netlib/http.py @@ -145,8 +145,11 @@ def parse_http_protocol(s): if "." not in version: return None major, minor = version.split('.') - major = int(major) - minor = int(minor) + try: + major = int(major) + minor = int(minor) + except ValueError: + return None return major, minor diff --git a/test/test_http.py b/test/test_http.py index 206fc4df..0174a4aa 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -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") |