Unverified Commit 6a7dcbe6 authored by Aaron Todd's avatar Aaron Todd Committed by GitHub
Browse files

backport connection poisoning to hyper 1.x client (#3795)

## 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 -->
https://github.com/smithy-lang/smithy-rs/issues/1925

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

See also:
* upstream support: https://github.com/hyperium/hyper-util/pull/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._
parent 8ccd2da8
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
---
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
+8 −8
Original line number Diff line number Diff line
@@ -404,7 +404,7 @@ dependencies = [

[[package]]
name = "aws-smithy-experimental"
version = "0.1.3"
version = "0.1.4"
dependencies = [
 "aws-smithy-async 1.2.1",
 "aws-smithy-runtime 1.6.3",
@@ -412,7 +412,7 @@ dependencies = [
 "aws-smithy-types 1.2.2",
 "h2 0.4.5",
 "http 1.1.0",
 "hyper 1.3.1",
 "hyper 1.4.1",
 "hyper-rustls 0.27.2",
 "hyper-util",
 "once_cell",
@@ -1862,9 +1862,9 @@ dependencies = [

[[package]]
name = "hyper"
version = "1.3.1"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d"
checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05"
dependencies = [
 "bytes",
 "futures-channel",
@@ -1904,7 +1904,7 @@ checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155"
dependencies = [
 "futures-util",
 "http 1.1.0",
 "hyper 1.3.1",
 "hyper 1.4.1",
 "hyper-util",
 "rustls 0.23.10",
 "rustls-native-certs 0.7.0",
@@ -1916,16 +1916,16 @@ dependencies = [

[[package]]
name = "hyper-util"
version = "0.1.5"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56"
checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9"
dependencies = [
 "bytes",
 "futures-channel",
 "futures-util",
 "http 1.1.0",
 "http-body 1.0.0",
 "hyper 1.3.1",
 "hyper 1.4.1",
 "pin-project-lite",
 "socket2",
 "tokio",
+3 −2
Original line number Diff line number Diff line
[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"
@@ -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 }
+10 −7
Original line number Diff line number Diff line
@@ -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::{
@@ -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;
@@ -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();
@@ -425,7 +428,7 @@ fn extract_smithy_connection(capture_conn: &CaptureConnection) -> Option<Connect
    } else {
        None
    }
}*/
}

impl<C> HttpConnector for Adapter<C>
where
@@ -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);