aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--netlib/http.py7
-rw-r--r--test/test_http.py2
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")