From: Joe Date: Sun, 2 Aug 2020 09:48:09 +0000 (+0800) Subject: Handle bare env proxy hostname gracefully (#1120) X-Git-Tag: 0.14.0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d76b2c2fb7241e5a21f6df86d6142790d4548b8c;p=thirdparty%2Fhttpx.git Handle bare env proxy hostname gracefully (#1120) --- diff --git a/httpx/_utils.py b/httpx/_utils.py index c2dc6a45..b09aebcf 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -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: diff --git a/tests/client/test_proxies.py b/tests/client/test_proxies.py index cffa75d5..3f014baa 100644 --- a/tests/client/test_proxies.py +++ b/tests/client/test_proxies.py @@ -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"},