[bitreq]: Add blocking Client with connection pooling#518
Open
tnull wants to merge 2 commits intorust-bitcoin:masterfrom
Open
[bitreq]: Add blocking Client with connection pooling#518tnull wants to merge 2 commits intorust-bitcoin:masterfrom
Client with connection pooling#518tnull wants to merge 2 commits intorust-bitcoin:masterfrom
Conversation
Add a blocking `Client` that is exposed when the `async` feature is *not* active. It mirrors the async `Client`'s API: an LRU-evicting pool of connections keyed by (https, host, port, proxy) that avoids repeated TCP handshakes and TLS negotiations. Key implementation details: - Replace `std::io::Bytes` with a custom `StreamBytes` iterator that allows recovering the underlying `HttpStream` via `into_buf_reader` after the response body has been fully read. - Add `Response::create_pooled` which reads the full body and returns `Option<HttpStream>` when `Connection: keep-alive` was indicated and the `BufReader` buffer is clean. - Add `Connection::from_stream` and `Connection::send_for_pool` to support wrapping a pooled stream and returning it after use. - The blocking `Client` handles HTTP redirects (301/302/303/307) in a loop, reusing the pool for each hop, and parses `Keep-Alive: timeout=N` to expire cached connections (default 60s). - Expose `Client` and `RequestExt` under `#[cfg(feature = "std")]` instead of `#[cfg(feature = "async")]` so the appropriate variant is available in both configurations. Co-Authored-By: HAL 9000
Make the `CLIENT` static unconditional and add a `#[cfg(not(feature = "async"))]` block that exercises the blocking `Client::send()` path, ensuring the connection-pooling client is tested regardless of feature configuration. Co-Authored-By: HAL 9000
Collaborator
oleonardolima
left a comment
There was a problem hiding this comment.
cACK 94c62c3
It looks good so far, though I won't be able to do a in-depth review and testing until early next week.
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.
Previously, we added a
Clientallowing for connection reuse behind theasyncfeature. Here we do the same for the blocking, i.e., non-asyncpath.