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

backport connection poisoning to hyper 1.x client #3795

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changelog/1724090349.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
applies_to:
- client
authors:
- aajtodd
references:
- smithy-rs#1925
breaking: false
new_feature: false
bug_fix: false
---
Backport connection poisoning to hyper 1.x support
16 changes: 8 additions & 8 deletions rust-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions rust-runtime/aws-smithy-experimental/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-experimental"
version = "0.1.3"
version = "0.1.4"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
description = "Experiments for the smithy-rs ecosystem"
edition = "2021"
Expand All @@ -15,10 +15,11 @@ crypto-aws-lc-fips = ["rustls/fips"]
[dependencies]
aws-smithy-types = { path = "../aws-smithy-types", features = ["http-body-1-x"] }
aws-smithy-runtime-api = { features = ["client", "http-1x"], path = "../aws-smithy-runtime-api" }
aws-smithy-runtime = { features = ["client"], path = "../aws-smithy-runtime" }
aws-smithy-async = { path = "../aws-smithy-async" }
hyper = { version = "1", features = ["client", "http1", "http2"] }
pin-project-lite = "0.2.13"
hyper-util = "0.1.3"
hyper-util = "0.1.7"
http = "1"
tokio = "1"
hyper-rustls = { version = "0.27", features = ["http2", "http1", "native-tokio", "tls12"], default-features = false }
Expand Down
17 changes: 10 additions & 7 deletions rust-runtime/aws-smithy-experimental/src/hyper_1_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

use aws_smithy_async::future::timeout::TimedOutError;
use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep};
use aws_smithy_runtime::client::http::connection_poisoning::CaptureSmithyConnection;
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::connection::ConnectionMetadata;
use aws_smithy_runtime_api::client::connector_metadata::ConnectorMetadata;
use aws_smithy_runtime_api::client::dns::ResolveDns;
use aws_smithy_runtime_api::client::http::{
Expand All @@ -24,11 +26,13 @@ use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::retry::ErrorKind;
use client::connect::Connection;
use h2::Reason;
use http::Uri;
use http::{Extensions, Uri};
use hyper::rt::{Read, Write};
use hyper_util::client::legacy as client;
use hyper_util::client::legacy::connect::dns::Name;
use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::{
capture_connection, CaptureConnection, Connect, HttpInfo,
};
use hyper_util::rt::TokioExecutor;
use rustls::crypto::CryptoProvider;
use std::borrow::Cow;
Expand Down Expand Up @@ -400,7 +404,6 @@ impl<C> fmt::Debug for Adapter<C> {
}
}

/*
/// Extract a smithy connection from a hyper CaptureConnection
fn extract_smithy_connection(capture_conn: &CaptureConnection) -> Option<ConnectionMetadata> {
let capture_conn = capture_conn.clone();
Expand All @@ -425,7 +428,7 @@ fn extract_smithy_connection(capture_conn: &CaptureConnection) -> Option<Connect
} else {
None
}
}*/
}

impl<C> HttpConnector for Adapter<C>
where
Expand All @@ -437,19 +440,19 @@ where
C::Error: Into<BoxError>,
{
fn call(&self, request: HttpRequest) -> HttpConnectorFuture {
let request = match request.try_into_http1x() {
let mut request = match request.try_into_http1x() {
Ok(request) => request,
Err(err) => {
return HttpConnectorFuture::ready(Err(ConnectorError::user(err.into())));
}
};
/*let capture_connection = capture_connection(&mut request);
let capture_connection = capture_connection(&mut request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel like this recently uncommented out chunk could use a comment for some context. Reading the CaptureConnection docs didn't quite clear it up for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is same as the hyper 0.14 implementation. CaptureConnection allows us to capture the actual connection used for the request (once established) and query it for information or in this case poison it so it isn't used again.

if let Some(capture_smithy_connection) =
request.extensions().get::<CaptureSmithyConnection>()
{
capture_smithy_connection
.set_connection_retriever(move || extract_smithy_connection(&capture_connection));
}*/
}
let mut client = self.client.clone();
use tower::Service;
let fut = client.call(request);
Expand Down