Fix no_proxy to support IPV6 CIDR format

no_proxy=fe11::/16 python -c 'import httpx; c = httpx.Client()'

Closes: #3221
This commit is contained in:
Bill Peck 2026-01-06 16:45:04 -05:00
parent ae1b9f6623
commit 3e53fe315d
No known key found for this signature in database
GPG Key ID: F179F385E3D1E013
2 changed files with 8 additions and 1 deletions

View File

@ -67,7 +67,13 @@ def get_environment_proxies() -> dict[str, str | None]:
elif is_ipv4_hostname(hostname):
mounts[f"all://{hostname}"] = None
elif is_ipv6_hostname(hostname):
mounts[f"all://[{hostname}]"] = None
if "/" in hostname:
CIDR = hostname.split("/")
hostname = f"{CIDR[0]}"
subnet = f"/{CIDR[1]}"
else:
subnet = ""
mounts[f"all://[{hostname}]{subnet}"] = None
elif hostname.lower() == "localhost":
mounts[f"all://{hostname}"] = None
else:

View File

@ -100,6 +100,7 @@ def test_logging_redirect_chain(server, caplog):
({"no_proxy": "127.0.0.1"}, {"all://127.0.0.1": None}),
({"no_proxy": "192.168.0.0/16"}, {"all://192.168.0.0/16": None}),
({"no_proxy": "::1"}, {"all://[::1]": None}),
({"no_proxy": "fe11::/16"}, {"all://[fe11::]/16": None}),
({"no_proxy": "localhost"}, {"all://localhost": None}),
({"no_proxy": "github.com"}, {"all://*github.com": None}),
({"no_proxy": ".github.com"}, {"all://*.github.com": None}),