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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 19, 2026

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing mbeijen:fix-no-proxy-cidr-matching (eb703b5) with main (c2a2b8d)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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>
@mbeijen mbeijen force-pushed the fix-no-proxy-cidr-matching branch from 13221ad to eb703b5 Compare May 24, 2026 14:32
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