Skip to content

Skip IP parsing for hostnames in CIDR proxy patterns - #1323

Open
patrick-immometrica wants to merge 2 commits into
pydantic:mainfrom
patrick-immometrica:no-proxy-match-speed
Open

patrick-immometrica wants to merge 2 commits into
pydantic:mainfrom
patrick-immometrica:no-proxy-match-speed

Conversation

@patrick-immometrica

@patrick-immometrica patrick-immometrica commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

With a CIDR entry in NO_PROXY (since #1165), URLPattern.matches() calls ipaddress.ip_address(other.host) for every request. For a normal hostname this raises and catches a ValueError once per CIDR mount. A common Kubernetes/corporate NO_PROXY has three of those, and the mounts are built even without any proxy configured.

An IP literal always starts with a digit (IPv4) or contains : (IPv6), so anything else can skip the parse.

Client._transport_for_url() for https://api.openai.com/... with NO_PROXY=localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local,.internal:

µs/call
main 5.15
this PR 1.21

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

View guided diff

@codspeed

codspeed Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 1 untouched benchmark
⏩ 24 skipped benchmarks1


Comparing patrick-immometrica:no-proxy-match-speed (c921e66) with main (f4f65c1)

Open in CodSpeed

Footnotes

  1. 24 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. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/httpx2/httpx2/_utils.py Resolved

This branch has not been deployed

No deployments
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