]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Raise TypeError if invalid parameter for HTTPVersionConfig (#253)
authorCan Sarıgöl <cansarigol@derinbilgi.com.tr>
Tue, 20 Aug 2019 22:39:05 +0000 (01:39 +0300)
committerSeth Michael Larson <sethmichaellarson@gmail.com>
Tue, 20 Aug 2019 22:39:05 +0000 (17:39 -0500)
httpx/config.py
tests/test_config.py

index b8544453d8df86e66d4e3ebba586ca6fcf8ddb25..4082a9f7aacd320fd78fd767012bb5cad8d50457 100644 (file)
@@ -251,8 +251,16 @@ class HTTPVersionConfig:
             self.http_versions = {http_versions.upper()}
         elif isinstance(http_versions, HTTPVersionConfig):
             self.http_versions = http_versions.http_versions
+        elif isinstance(http_versions, typing.Iterable):
+            self.http_versions = {
+                version.upper() if isinstance(version, str) else version
+                for version in http_versions
+            }
         else:
-            self.http_versions = {version.upper() for version in http_versions}
+            raise TypeError(
+                f"HTTP version should be a string or list of strings, "
+                "but got {type(http_versions)}"
+            )
 
         for version in self.http_versions:
             if version not in ("HTTP/1.1", "HTTP/2"):
index 6a862fd16af701da8091b31d238b6bee9299fd58..0df1029b86fa3a9e8b151bd512672ff22d581f34 100644 (file)
@@ -115,6 +115,16 @@ def test_invalid_http_version():
         httpx.HTTPVersionConfig("HTTP/9")
 
 
+def test_invalid_http_version_type():
+    with pytest.raises(TypeError):
+        httpx.HTTPVersionConfig(123)
+
+
+def test_invalid_http_version_list_type():
+    with pytest.raises(ValueError):
+        httpx.HTTPVersionConfig([123])
+
+
 def test_empty_http_version():
     with pytest.raises(ValueError):
         httpx.HTTPVersionConfig([])