Skip to content

Commit

Permalink
Make rustls and native_tls client builder helpers dyn (#1217)
Browse files Browse the repository at this point in the history
* Make `rustls` and `native_tls` client builder helpers dyn

* Update changelog
  • Loading branch information
jdisanti authored Feb 23, 2022
1 parent 97a49f3 commit 8018080
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
29 changes: 21 additions & 8 deletions rust-runtime/aws-smithy-client/src/hyper_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
))
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8018080

Please sign in to comment.