Skip to content

Add IPNetPattern for accurate CIDR proxy/mount matching#969

Open
mbeijen wants to merge 1 commit into
pydantic:mainfrom
mbeijen:fix-no-proxy-cidr-matching
Open

Add IPNetPattern for accurate CIDR proxy/mount matching#969
mbeijen wants to merge 1 commit into
pydantic:mainfrom
mbeijen:fix-no-proxy-cidr-matching

Conversation

@mbeijen
Copy link
Copy Markdown
Contributor

@mbeijen mbeijen commented May 19, 2026

Setting no_proxy patterns matched by hostname string comparison. So 192.168.0.1 would not match all://192.168.0.0/16.

Add IPNetPattern, backed by ipaddress.ip_network, and a build_url_pattern() factory that returns IPNetPattern for all:// patterns containing a slash and WildcardURLPattern otherwise. Introduce a Pattern protocol so Client and AsyncClient can hold either kind in their _mounts dict.

URLPattern is kept as a backward-compatible alias for WildcardURLPattern.

Together with #967 will close

Ported from encode/httpx#3741.

Setting no_proxy patterns matched by hostname string comparison.
So 192.168.0.1 would not match all://192.168.0.0/16.

Add IPNetPattern, backed by ipaddress.ip_network, and a build_url_pattern()
factory that returns IPNetPattern for all:// patterns containing a slash and
WildcardURLPattern otherwise. Introduce a Pattern protocol so Client and
AsyncClient can hold either kind in their _mounts dict.

URLPattern is kept as a backward-compatible alias for WildcardURLPattern.

Together with pydantic#967 will close
 - pydantic#829
 - pydantic#899

Ported from encode/httpx#3741.

Co-Authored-By: Ondrej Filip <ondrej.filip@firma.seznam.cz>
Co-Authored-By: Bill Peck <bpeck@redhat.com>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 19, 2026

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing mbeijen:fix-no-proxy-cidr-matching (13221ad) with main (c1d3d95)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant