From 2fb3053cd279d068950ebfbfc3e25da0513567c8 Mon Sep 17 00:00:00 2001 From: "Michiel W. Beijen" Date: Mon, 18 May 2026 21:51:53 +0200 Subject: [PATCH] Fix no_proxy IPv6 CIDR crash in get_environment_proxies no_proxy=fe80::/10 (or any IPv6 CIDR) crashed Client() construction because get_environment_proxies() bracketed the whole string including the CIDR suffix, producing the invalid URL pattern "all://[fe80::/10]". Bracket only the address portion and append the suffix outside the brackets. Closes #899. Upstream: https://github.com/encode/httpx/issues/3574 --- src/httpx2/httpx2/_utils.py | 6 +++++- tests/httpx2/test_utils.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/httpx2/httpx2/_utils.py b/src/httpx2/httpx2/_utils.py index eef7b6dc..5444622b 100644 --- a/src/httpx2/httpx2/_utils.py +++ b/src/httpx2/httpx2/_utils.py @@ -65,7 +65,11 @@ 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: + addr, _, subnet = hostname.partition("/") + mounts[f"all://[{addr}]/{subnet}"] = None + else: + mounts[f"all://[{hostname}]"] = None elif hostname.lower() == "localhost": mounts[f"all://{hostname}"] = None else: diff --git a/tests/httpx2/test_utils.py b/tests/httpx2/test_utils.py index f4bbd1fa..8efbfc53 100644 --- a/tests/httpx2/test_utils.py +++ b/tests/httpx2/test_utils.py @@ -99,6 +99,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}),