Repository navigation
Conversation
A `NO_PROXY` entry may spell an IPv6 address the way a URL does, in brackets, optionally followed by a port or a prefix length. That spelling does not satisfy `is_ipv6_hostname`, so the entry fell through to the host-wildcard branch and produced `all://*[::1]`. That is not a parseable URL pattern, so constructing a client raised `InvalidURL: Invalid port: ':1]'` before any request was made. Recognize the bracketed form before dispatching, so it produces the same mount as the unbracketed spelling. This covers a bare address inside the brackets only - `is_ipv6_hostname` ignores anything after a `/`, so the check requires the bracketed part to be the whole address. Entry spellings that are malformed rather than bracketed, such as `[not:ipv6]`, still reach the wildcard branch, and an entry carrying a non-numeric port still fails to parse. Both are unchanged here.
Merging this PR will not alter performance
Comparing Footnotes
|
Member
|
Superseded by #1267. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Recognize bracketed IPv6 literals in
NO_PROXYbefore the hostname-wildcard fallback, preventing valid entries such as[::1]and[::1]:8080from aborting client construction.all://*[::1]is not a parseable URL pattern, soClient()andAsyncClient()raisedInvalidURL: Invalid port: ':1]'before any request was made.This change does not add general handling for malformed entries, or CIDR/network matching —
URLPattern.matchesdoes not consider a prefix length, which is what #969 covers.Raised in discussion #1241. That thread and this PR were posted together; I am happy to hold the implementation until the thread settles, or to adjust it based on the feedback there.
What changed
src/httpx2/httpx2/_utils.py: a bracketed entry whose bracketed part is a bare IPv6 address is recognized before the dispatch, producing the same mount as the unbracketed spelling. The check requires the bracketed part to be the whole address, becauseis_ipv6_hostnameignores anything after a/.tests/httpx2/test_utils.py: three cases covering[::1],[::1]:8080,[::1]/128.tests/httpx2/client/test_proxies.py: client-construction and transport-selection cases for both client classes, including that[::1]:8080does not bypass another port, and that[::1]does not bypass another IPv6 address.Verification
_utils.pychange fails exactly the three newtest_utils.pycases and all twelvetest_proxies.pycases; nothing else changes.scripts/checkexits 0; full suite2026 passed, 1 skipped.urllib.request.getproxies()falls back toscutiland makes the pre-existingtest_get_environment_proxiesparametrizations fail regardless of this change. To match Linux CI I unset the proxy environment variables and neutralizedgetproxies_macosx_sysconfviasitecustomize.py. This is not the same as having run on Linux CI.Separate issue found while testing
Pre-existing, not addressed here: a
NO_PROXYentry that names a scheme's default port never matches, because the request URL normalizes that port toNonewhile the pattern keeps it. This affects IPv4 and domain entries as well, and it can also over-match from the other direction. Happy to file it separately.Checklist
The documentation box is left unticked: this changes no public API and no documented behaviour contract — it fixes the parsing of an existing configuration. Happy to add a changelog entry or a docs note if the project requires one.