Unverified Commit 80180806 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Make `rustls` and `native_tls` client builder helpers dyn (#1217)

* Make `rustls` and `native_tls` client builder helpers dyn

* Update changelog
parent 97a49f3c
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -34,3 +34,15 @@ message = "`aws_smithy_types::primitive::Encoder` is now a struct rather than an
references = ["smithy-rs#1209"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = "`ClientBuilder` helpers `rustls()` and `native_tls()` now return `DynConnector` and use dynamic dispatch rather than returning their concrete connector type that would allow static dispatch. If static dispatch is desired, then manually construct a connector to give to the builder. For example, for rustls: `builder.connector(Adapter::builder().build(aws_smithy_client::conns::https()))` (where `Adapter` is in `aws_smithy_client::hyper_ext`)."
references = ["smithy-rs#1217"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[aws-sdk-rust]]
message = "`ClientBuilder` helpers `rustls()` and `native_tls()` now return `DynConnector` so that they once again work when constructing clients with custom middleware in the SDK."
references = ["smithy-rs#1217", "aws-sdk-rust#467"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "jdisanti"
+21 −8
Original line number Diff line number Diff line
@@ -304,19 +304,22 @@ where

#[cfg(feature = "rustls")]
impl<M, R> ClientBuilder<(), M, R> {
    /// Connect to the service over HTTPS using Rustls.
    pub fn rustls(self) -> ClientBuilder<Adapter<crate::conns::Https>, M, R> {
        self.connector(Adapter::builder().build(crate::conns::https()))
    /// Connect to the service over HTTPS using Rustls using dynamic dispatch.
    pub fn rustls(self) -> ClientBuilder<DynConnector, M, R> {
        self.connector(DynConnector::new(
            Adapter::builder().build(crate::conns::https()),
        ))
    }
}

#[cfg(feature = "native-tls")]
impl<M, R> ClientBuilder<(), M, R> {
    /// Connect to the service over HTTPS using the native TLS library on your platform.
    pub fn native_tls(
        self,
    ) -> ClientBuilder<Adapter<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>, M, R> {
        self.connector(Adapter::builder().build(crate::conns::native_tls()))
    /// Connect to the service over HTTPS using the native TLS library on your
    /// platform using dynamic dispatch.
    pub fn native_tls(self) -> ClientBuilder<DynConnector, M, R> {
        self.connector(DynConnector::new(
            Adapter::builder().build(crate::conns::native_tls()),
        ))
    }
}

@@ -632,8 +635,18 @@ mod test {

    use aws_smithy_http::body::SdkBody;

    use super::ClientBuilder;
    use crate::erase::DynConnector;
    use crate::hyper_ext::Adapter;

    #[test]
    fn builder_connection_helpers_are_dyn() {
        #[cfg(feature = "rustls")]
        let _builder: ClientBuilder<DynConnector, (), _> = ClientBuilder::new().rustls();
        #[cfg(feature = "native-tls")]
        let _builder: ClientBuilder<DynConnector, (), _> = ClientBuilder::new().native_tls();
    }

    #[tokio::test]
    async fn hyper_io_error() {
        let connector = TestConnection {