]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Handle bare env proxy hostname gracefully (#1120)
authorJoe <nigelchiang@outlook.com>
Sun, 2 Aug 2020 09:48:09 +0000 (17:48 +0800)
committerGitHub <noreply@github.com>
Sun, 2 Aug 2020 09:48:09 +0000 (10:48 +0100)
httpx/_utils.py
tests/client/test_proxies.py

index c2dc6a453b48da85a9c06475fb3a7c313245c957..b09aebcfd78a052f21cccd850e34a96899c59d14 100644 (file)
@@ -311,7 +311,8 @@ def get_environment_proxies() -> typing.Dict[str, typing.Optional[str]]:
 
     for scheme in ("http", "https", "all"):
         if proxy_info.get(scheme):
-            mounts[scheme] = proxy_info[scheme]
+            hostname = proxy_info[scheme]
+            mounts[scheme] = hostname if "://" in hostname else f"http://{hostname}"
 
     no_proxy_hosts = [host.strip() for host in proxy_info.get("no", "").split(",")]
     for hostname in no_proxy_hosts:
index cffa75d5d6105ad633a78c26d8de1e11dcb0e63b..3f014baa9694a53c3b4ae22301c3ef497872c719 100644 (file)
@@ -143,6 +143,8 @@ def test_unsupported_proxy_scheme():
             {"HTTP_PROXY": "http://example.com"},
             "http://example.com",
         ),
+        # Auto prepend http scheme
+        ("http://google.com", {"HTTP_PROXY": "example.com"}, "http://example.com"),
         (
             "http://google.com",
             {"HTTP_PROXY": "http://example.com", "NO_PROXY": "google.com"},