From 8bedf2bcc44996b1c4a763054a7c943e03f18272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 16:51:26 +0800 Subject: [PATCH 1/2] Treat CIDR tokens in NO_PROXY the way modern curl does. --- src/whichproxy/match.py | 9 +++++++++ tests/test_match.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/whichproxy/match.py b/src/whichproxy/match.py index 0a795d4..8ab4bac 100644 --- a/src/whichproxy/match.py +++ b/src/whichproxy/match.py @@ -73,6 +73,15 @@ def _curl_match(host: str, tokens: list[str]) -> str | None: continue if raw == "*": return "matched *" + if "/" in raw: + try: + network = ipaddress.ip_network(raw, strict=False) + addr = ipaddress.ip_address(host) + except ValueError: + continue + if addr in network: + return f"CIDR {raw}" + continue if raw.startswith("."): suffix = raw.lower().lstrip(".") if host.endswith("." + suffix): diff --git a/tests/test_match.py b/tests/test_match.py index 2c311d9..bcef11a 100644 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -40,6 +40,14 @@ def test_go_bare_openai_matches_apex_and_subdomain() -> None: assert sub["go"].route == "DIRECT" +def test_curl_cidr_matches_like_modern_curl() -> None: + inside = _by_model("10.0.0.8", "10.0.0.0/8") + outside = _by_model("11.1.1.1", "10.0.0.0/8") + assert inside["curl"].route == "DIRECT" + assert "CIDR" in inside["curl"].reason + assert outside["curl"].route == "PROXY" + + def test_star_matches_all_curl_and_go_direct() -> None: results = _by_model("api.openai.com", "*") assert results["curl"].route == "DIRECT" From f0c5504501f97ce1eb563f2fab89584084740992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E3=81=AE=E5=92=B8=E9=B1=BC?= <3129538298@qq.com> Date: Wed, 26 Aug 2026 17:38:17 +0800 Subject: [PATCH 2/2] Cover IPv6 CIDR tokens in the curl NO_PROXY model. --- tests/test_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_match.py b/tests/test_match.py index bcef11a..99b6a2d 100644 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -48,6 +48,14 @@ def test_curl_cidr_matches_like_modern_curl() -> None: assert outside["curl"].route == "PROXY" +def test_curl_ipv6_cidr_matches_like_modern_curl() -> None: + inside = _by_model("[fd00::1]", "fd00::/8") + outside = _by_model("[2001:db8::1]", "fd00::/8") + assert inside["curl"].route == "DIRECT" + assert "CIDR" in inside["curl"].reason + assert outside["curl"].route == "PROXY" + + def test_star_matches_all_curl_and_go_direct() -> None: results = _by_model("api.openai.com", "*") assert results["curl"].route == "DIRECT"