Module aws_smithy_client::hyper_ext
source · [−]Expand description
Implementation of SmithyConnector
for Hyper
The module provides Adapter
which enables using a hyper::Client
as the connector for a Smithy
Client
.
Examples
Construct a Smithy Client with Hyper and Rustls
In the basic case, customers should not need to use this module. A default implementation of Hyper
with rustls
will be constructed during client creation. However, if you are creating a Smithy
Client
, directly, use the https()
method to match the default behavior:
use aws_smithy_client::Builder;
use aws_smithy_client::erase::DynConnector;
// Replace this with your middleware type
type MyMiddleware = tower::layer::util::Identity;
let client = Builder::<DynConnector, MyMiddleware>::dyn_https().build();
Create a Hyper client with a custom timeout
One common use case for constructing a connector directly is setting CONNECT
timeouts. Since the
internal connector is cheap to clone, you can also use this to share a connector between multiple services.
use std::time::Duration;
use aws_smithy_client::{Client, conns, hyper_ext};
use aws_smithy_client::erase::DynConnector;
use aws_smithy_types::timeout;
let timeout = timeout::Http::new().with_connect_timeout(Some(Duration::from_secs(1)).into());
let connector = hyper_ext::Adapter::builder().timeout(&timeout).build(conns::https());
// Replace this with your middleware
type MyMiddleware = tower::layer::util::Identity;
// once you have a connector, use it to construct a Smithy client:
let client = Client::<DynConnector, MyMiddleware>::new(DynConnector::new(connector));
Structs
Adapter from a hyper::Client
to a connector usable by a Smithy Client
.
Builder for hyper_ext::Adapter