fix: Unify the request pipeline and retry policy across HTTP clients - #1006
Draft
vdusek wants to merge 3 commits into
Draft
fix: Unify the request pipeline and retry policy across HTTP clients#1006vdusek wants to merge 3 commits into
vdusek wants to merge 3 commits into
Conversation
Move `call`, the retry loop, and the per-attempt request handling from `ImpitHttpClient` into `HttpClient` and `HttpClientAsync`, leaving Impit as a thin adapter over the `send_request`, error-classification, and lifecycle hooks. A custom client that overrides `call` keeps working unchanged and opts out of the shared pipeline. The same pass fixes: - Transport errors a retry cannot fix (`UnsupportedProtocol`, `LocalProtocolError`, `TooManyRedirects`) fail on the first attempt instead of burning the whole backoff. Every other error in the `impit.HTTPError` tree stays retryable, including a bare `HTTPError` from a body that ends mid-chunk and a `ProxyError` from a proxy answering CONNECT with a transient status. - A failure while reading a streamed error response is classified and retried like a send failure, and the response is closed instead of being left open. - `HttpResponse` comes from `typing_extensions`, whose runtime protocol check looks attributes up statically, so `isinstance(response, HttpResponse)` no longer buffers or rejects an unread streaming body. - `try_import` only substitutes failed imports for the optional dependency it names, so an `ImportError` from the importing module or another dependency is no longer masked, and `__all__` omits what a missing extra never provided.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1006 +/- ##
==========================================
+ Coverage 94.86% 94.91% +0.04%
==========================================
Files 58 58
Lines 5357 5406 +49
==========================================
+ Hits 5082 5131 +49
Misses 275 275
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Moves
call, the retry loop, and the per-attempt request handling fromImpitHttpClientintoHttpClientandHttpClientAsync, leaving Impit as a thin adapter over the transport hooks:send_request,is_retryable_transport_error,is_timeout_error, andclose()/aclose()plus context managers. A custom client that overridescallkeeps working unchanged and opts out of the shared pipeline.The same pass fixes:
UnsupportedProtocol,LocalProtocolError,TooManyRedirects) fail on the first attempt instead of burning the whole backoff. Everything else in theimpit.HTTPErrortree stays retryable, including a bareHTTPErrorfrom a body that ends mid-chunk and aProxyErrorfrom a proxy answering CONNECT with a transient status.HttpResponsecomes fromtyping_extensions, whose runtime protocol check looks attributes up statically, soisinstance(response, HttpResponse)no longer buffers or rejects an unread streaming body.try_importonly substitutes failed imports for the optional dependency it names, so anImportErrorfrom the importing module or another dependency is no longer masked, and__all__omits what a missing extra never provided.Split out of #1004, which adds the built-in HTTPX client on top of this contract.
✍️ Drafted by Claude Code