pub struct HttpClientBuilder { /* private fields */ }Expand description
An HTTP client builder.
Provides an ergonomic builder API for configuring an HTTP client.
§Defaults
A number of sensible defaults are provided:
- support for both HTTP and HTTPS (uses platform’s root certificates for server certificate validation)
- support for both HTTP/1.1 and HTTP/2 (automatically negotiated via ALPN)
- non-infinite timeouts for various stages of the request lifecycle (30 second connect timeout, 60 second per-request timeout)
- connection pool for reusing connections (45 second idle connection timeout, and a maximum of 5 idle connections per host)
- support for FIPS-compliant cryptography (if the
fipsfeature is enabled in thesaluki-tlscrate) via AWS-LC
Implementations§
Source§impl HttpClientBuilder
impl HttpClientBuilder
Sourcepub fn with_connect_timeout(self, timeout: Duration) -> Self
pub fn with_connect_timeout(self, timeout: Duration) -> Self
Sets the timeout when connecting to the remote host.
Defaults to 30 seconds.
Sourcepub fn with_request_timeout(self, timeout: Duration) -> Self
pub fn with_request_timeout(self, timeout: Duration) -> Self
Sets the per-request timeout.
The request timeout applies to each individual request made to the remote host, including each request made when retrying a failed request.
Defaults to 20 seconds.
Sourcepub fn without_request_timeout(self) -> Self
pub fn without_request_timeout(self) -> Self
Allow requests to run indefinitely.
This means there will be no overall timeout for the request, but the request still may be subject to other configuration settings, such as the connect timeout or retry policy.
Sourcepub fn with_connection_age_limit<L>(self, limit: L) -> Self
pub fn with_connection_age_limit<L>(self, limit: L) -> Self
Sets the maximum age of a connection before it is closed.
This is distinct from the maximum idle time: if any connection’s age exceeds limit, it will be closed rather
than being reused and added to the idle connection pool.
Defaults to no limit.
Sourcepub fn with_max_idle_conns_per_host(self, max: usize) -> Self
pub fn with_max_idle_conns_per_host(self, max: usize) -> Self
Sets the maximum number of idle connections per host.
Defaults to 5.
Sourcepub fn with_idle_conn_timeout(self, timeout: Duration) -> Self
pub fn with_idle_conn_timeout(self, timeout: Duration) -> Self
Sets the idle connection timeout.
Once a connection has been idle in the pool for longer than this duration, it will be closed and removed from the pool.
Defaults to 45 seconds.
Sourcepub fn with_proxies(self, proxies: Vec<Proxy>) -> Self
pub fn with_proxies(self, proxies: Vec<Proxy>) -> Self
Sets the proxies to be used for outgoing requests.
Defaults to no proxies. (i.e requests will be sent directly without using a proxy).
Sourcepub fn with_endpoint_telemetry<F>(
self,
metrics_builder: MetricsBuilder,
endpoint_name_fn: Option<F>,
) -> Self
pub fn with_endpoint_telemetry<F>( self, metrics_builder: MetricsBuilder, endpoint_name_fn: Option<F>, ) -> Self
Enables per-endpoint telemetry for HTTP transactions.
See EndpointTelemetryLayer for more information.
Sourcepub fn with_unix_socket_path<P: Into<PathBuf>>(self, path: P) -> Self
pub fn with_unix_socket_path<P: Into<PathBuf>>(self, path: P) -> Self
Sets a Unix domain socket path to route all connections through.
When set, the client will connect to this Unix socket instead of performing DNS resolution and TCP connection. The URI host is ignored — all requests are sent through the configured socket.
Defaults to unset (TCP connections via DNS).
Sourcepub fn with_tls_config<F>(self, f: F) -> Self
pub fn with_tls_config<F>(self, f: F) -> Self
Sets the TLS configuration.
A TLS configuration builder is provided to allow for more advanced configuration of the TLS connection.
Sourcepub fn with_hyper_config<F>(self, f: F) -> Self
pub fn with_hyper_config<F>(self, f: F) -> Self
Sets the underlying Hyper client configuration.
This is provided to allow for more advanced configuration of the Hyper client itself, and should generally be used sparingly.
Sourcepub fn with_bytes_sent_counter(self, counter: Counter) -> Self
pub fn with_bytes_sent_counter(self, counter: Counter) -> Self
Sets a counter that gets incremented with the number of bytes sent over the connection.
This tracks bytes sent at the HTTP client level, which includes headers and body but does not include underlying transport overhead, such as TLS handshaking, and so on.
Defaults to unset.
Sourcepub fn build(self) -> Result<HttpClient, GenericError>
pub fn build(self) -> Result<HttpClient, GenericError>
Builds the HttpClient.
§Errors
If there was an error building the TLS configuration for the client, an error will be returned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpClientBuilder
impl !RefUnwindSafe for HttpClientBuilder
impl Send for HttpClientBuilder
impl Sync for HttpClientBuilder
impl Unpin for HttpClientBuilder
impl UnsafeUnpin for HttpClientBuilder
impl !UnwindSafe for HttpClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked wrapper. Read moreSource§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked wrapper. Read more