From: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:04:04 +0000 (-0500) Subject: Fix environment proxies (#2741) X-Git-Tag: 0.26.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b9060ee1121b48669e0b30045c9344065f4f2ae;p=thirdparty%2Fhttpx.git Fix environment proxies (#2741) * Add red test * Make the test pass * Lint * chanelog --------- Co-authored-by: Karen Petrosyan <92274156+karosis88@users.noreply.github.com> Co-authored-by: Tom Christie --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 18d0e84a..950d3898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed +* Handle `NO_PROXY` envvar cases when a fully qualified URL is supplied as the value. (#2741) * Allow URLs where username or password contains unescaped '@'. (#2986) * Ensure ASGI `raw_path` does not include URL query component. (#2999) * Ensure `Response.iter_text()` cannot yield empty strings. (#2998) diff --git a/httpx/_utils.py b/httpx/_utils.py index a0bc2c5b..21241967 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -227,7 +227,9 @@ def get_environment_proxies() -> typing.Dict[str, typing.Optional[str]]: # (But not "wwwgoogle.com") # NO_PROXY can include domains, IPv6, IPv4 addresses and "localhost" # NO_PROXY=example.com,::1,localhost,192.168.0.0/16 - if is_ipv4_hostname(hostname): + if "://" in hostname: + mounts[hostname] = None + elif is_ipv4_hostname(hostname): mounts[f"all://{hostname}"] = None elif is_ipv6_hostname(hostname): mounts[f"all://[{hostname}]"] = None diff --git a/tests/test_utils.py b/tests/test_utils.py index bbaf6007..5391f9c2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -197,6 +197,7 @@ def test_get_ssl_cert_file(): ({"no_proxy": "localhost"}, {"all://localhost": None}), ({"no_proxy": "github.com"}, {"all://*github.com": None}), ({"no_proxy": ".github.com"}, {"all://*.github.com": None}), + ({"no_proxy": "http://github.com"}, {"http://github.com": None}), ], ) def test_get_environment_proxies(environment, proxies):