Add IPNetPattern for accurate CIDR proxy/mount matching

Closed
MB
7d ago
+128-26

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 https://github.com/pydantic/httpx2/pull/967 will close

Ported from https://github.com/encode/httpx/pull/3741.