feat: forward every httpx2 client option to the owned client - #148
Merged
Merged
Conversation
AsyncClient and Client forwarded only seven httpx2 client keywords, so setting verify (or proxy, http2, transport, ...) meant building the httpx2 client by hand and closing it yourself. Every option is now forwarded, typed via Unpack[TypedDict]; cert and event_hooks are refused, and follow_redirects=True with max_response_body_bytes raises ValueError.
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.
Problem
AsyncClientandClientforwarded only seven httpx2 client keywords (base_url,headers,params,cookies,timeout,limits,auth). Anything else, most oftenverifyfor a custom CA, meant building the httpx2 client by hand and passing it ashttpx2_client=. That cost more than one argument:TypeErrorclose()/aclose()and the context manager no longer closed itChange
The constructors take
**httpx2_options: Unpack[_AsyncClientOptions](_ClientOptionsfor sync) and forward every httpx2 client keyword to the client they build and own. The seven existing options keep their types, so call sites are unchanged. Three per-option helpers are replaced by one_select_httpx2_options.A named parameter per option was rejected because each one had to be listed three times (signature, conflict check, assembly). An untyped
httpx2_client_kwargs=dict was rejected because it gives up type checking.Refused and restricted options
certis refused: httpx2 deprecates it in favour of anssl.SSLContextpassed asverify.verify=<str>is excluded from the type for the same reason.event_hooksis refused: hooks run below the middleware chain, so anhttpx2.HTTPErrorraised in a hook reaches retry and the circuit breaker asTransportError. Middleware covers the use case.follow_redirects=Truewithmax_response_body_bytesraisesValueError, because httpx2 reads intermediate redirect bodies with an unboundedresponse.read()(up tomax_redirects).None, emptybase_url) are dropped, not forwarded. To httpware,timeout=Nonehas always meant "httpx2 default (5s)"; to httpx2 it means "no timeout". Forwarding it would silently remove timeouts.Type checking
A spike showed
ty0.0.84 checks value types underUnpack[TypedDict]but does not flag unknown keys (pyright and mypy do). The constructor therefore rejects unknown keys at runtime.Behaviour change
A caller-provided
httpx2_clientwithfollow_redirects=Truecombined withmax_response_body_bytesnow raisesValueError. It was accepted before, but the cap did not cover redirect bodies.Docs
docs/index.md: option forwarding, with averifyexample and when to usehttpx2_client=docs/testing.md: mock withtransport=instead of a hand-builthttpx2_client=docs/errors.md: the redirect restrictionAGENTS.md: the testing patternTests
tests/test_client_options.py, written first, covers both worlds:httpx2_client=TypeErrortransport=keeps the client ownedTests for the deleted helpers were removed. Full suite (955 passed, 100% coverage), ruff, ty, eof-fixer and
mkdocs build --strictpass locally.