Skip to content

Commit 3e53fe3

Browse files
committed
Fix no_proxy to support IPV6 CIDR format
no_proxy=fe11::/16 python -c 'import httpx; c = httpx.Client()' Closes: #3221
1 parent ae1b9f6 commit 3e53fe3

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

httpx/_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ def get_environment_proxies() -> dict[str, str | None]:
6767
elif is_ipv4_hostname(hostname):
6868
mounts[f"all://{hostname}"] = None
6969
elif is_ipv6_hostname(hostname):
70-
mounts[f"all://[{hostname}]"] = None
70+
if "/" in hostname:
71+
CIDR = hostname.split("/")
72+
hostname = f"{CIDR[0]}"
73+
subnet = f"/{CIDR[1]}"
74+
else:
75+
subnet = ""
76+
mounts[f"all://[{hostname}]{subnet}"] = None
7177
elif hostname.lower() == "localhost":
7278
mounts[f"all://{hostname}"] = None
7379
else:

tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_logging_redirect_chain(server, caplog):
100100
({"no_proxy": "127.0.0.1"}, {"all://127.0.0.1": None}),
101101
({"no_proxy": "192.168.0.0/16"}, {"all://192.168.0.0/16": None}),
102102
({"no_proxy": "::1"}, {"all://[::1]": None}),
103+
({"no_proxy": "fe11::/16"}, {"all://[fe11::]/16": None}),
103104
({"no_proxy": "localhost"}, {"all://localhost": None}),
104105
({"no_proxy": "github.com"}, {"all://*github.com": None}),
105106
({"no_proxy": ".github.com"}, {"all://*.github.com": None}),

0 commit comments

Comments
 (0)