Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add capture_connection #3144

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

rcoh
Copy link

@rcoh rcoh commented Feb 14, 2023

Add capture_connection functionality. This allows callers to retrieve the Connected struct of the connection that was used internally by Hyper. This is in service of #2605.

This pairs with a coming PR that adds a poison API to Connected — the pair of these APIs makes it possible to avoid reusing connections that the client deems to be bad.

Example usage:

use hyper::client::connect::{capture_connection, CaptureConnection};
let mut request = http::Request::builder()
   .uri("http://foo.com")
   .body(())
   .unwrap();

let captured_connection = capture_connection(&mut request);

let client = hyper::Client::new();
// success or failure, it will still work fine.
let _ = client.request(request).await;

let connection_info = capture_connection.connection_metadata();

Although this uses http::Extensions under the hood, the API exposed explicitly hides that detail.

/// client.request(request).await.expect("request failed");
/// # }
/// ```
pub fn capture_connection<B>(request: &mut crate::http::Request<B>) -> CaptureConnection {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extension trait?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, will defer for now but could add later

@@ -115,6 +118,114 @@ pub struct Connected {
pub(super) extra: Option<Extra>,
}

/// [`CaptureConnection`] allows callers to capture [`Connected`] information
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to live in this file or can we move it out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can definitely be moved—any preference for final location?

Add `capture_connection` functionality. This allows callers to retrieve the `Connected` struct of the connection that was used internally by Hyper. This is in service of hyperium#2605.

Although this uses `http::Extensions` under the hood, the API exposed explicitly hides that detail.
Copy link
Member

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks real clear to me, love it!

@seanmonstar seanmonstar merged commit c849339 into hyperium:0.14.x Feb 22, 2023
oddgrd pushed a commit to oddgrd/hyper that referenced this pull request Mar 7, 2023
)

Add `capture_connection` functionality. This allows callers to retrieve the `Connected` struct of the connection that was used internally by Hyper. This is in service of hyperium#2605.

Although this uses `http::Extensions` under the hood, the API exposed explicitly hides that detail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants