refactor!: normalize responses into a shared HttpResponse - #243
Open
MaxFangX wants to merge 1 commit into
Open
Conversation
Normalize responses into a private HttpResponse (status + fully-read body) as soon as they leave the HTTP client, so the retry loops, status checking, and all endpoint methods are backend-agnostic. Only the code producing an HttpResponse now touches bitreq types, preparing to swap in alternative HTTP transports (see bitcoindevkit#97). Also deletes the bitreq::Response status predicates, four of which were dead code. Breaking: - BlockingClient::post_request is now private (it returned the raw bitreq::Response). - JSON and UTF-8 decode errors are now reported via Error::SerdeJson and a new Error::InvalidUtf8 variant rather than wrapped bitreq errors. License: MIT OR Apache-2.0
MaxFangX
force-pushed
the
max/08-17-extract-http-response
branch
from
August 18, 2026 03:27
ccf6513 to
22505c7
Compare
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.
#97 plans to abstract the HTTP client away. This PR makes progress towards
that goal by centralizing response handling in one client-agnostic type, so
that only the code producing it touches the underlying HTTP client.
Additional motivation: To address the immediate performance and reliability
problems caused by the switch to
bitreq(outlined in rust-bitcoin/corepc#587),Lexe needs to switch back to using
reqwestas our underlying HTTP client.After #241, it looks like a patch to add
reqwestback in under an opt-infeature flag unlikely to be upstreamed, so Lexe will need to maintain a fork of
rust-esplora-client. This refactor has minimal logic changes but makes themaintenance of our fork a bit easier for us.
Concretely, responses are normalized into a private
HttpResponse(status +fully-read body) as soon as they leave the HTTP client. Retry loops, status
checking, and all endpoint methods in both clients now operate on this shared
type, so swapping the HTTP client (whether for our reqwest patch or for #97)
only touches the few functions that produce an
HttpResponse.The refactor also DRYs up the status checking and error construction previously
duplicated across both async and blocking clients, and deletes the
bitreq::Responsestatus predicates, four of which were dead code.Net -34 lines.
Breaking changes:
BlockingClient::post_requestis now private (it returned a rawbitreq::Response).Error::SerdeJsonand anew
Error::InvalidUtf8variant rather than wrapped bitreq errors.