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

Make rustls and native_tls client builder helpers dyn #1217

Merged
merged 3 commits into from
Feb 23, 2022
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.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()),
))
Comment on lines +307 to +322
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should examples in these methods about how not to use them when required (basically including examples of custom HTTPS, or at least linking to them)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Filed an issue for improving these docs overall: awslabs/aws-sdk-rust#469

}
}

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