Skip to content

Commit

Permalink
backport connection poisoning to hyper 1.x client (#3795)
Browse files Browse the repository at this point in the history
## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->
#1925

## Description
Backports connection poisoning that hyper 0.14 HTTP client has to the
hyper 1.x client.

See also:
* upstream support: hyperium/hyper-util#121

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [X] For changes to the smithy-rs codegen or runtime crates, I have
created a changelog entry Markdown file in the `.changelog` directory,
specifying "client," "server," or both in the `applies_to` key.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
aajtodd authored Aug 21, 2024
1 parent 8ccd2da commit 6a7dcbe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
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 <[email protected]>"]
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);
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

0 comments on commit 6a7dcbe

Please sign in to comment.