Skip to main content

HttpClientBuilder

Struct HttpClientBuilder 

Source
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 fips feature is enabled in the saluki-tls crate) via AWS-LC

Implementations§

Source§

impl HttpClientBuilder

Source

pub fn with_connect_timeout(self, timeout: Duration) -> Self

Sets the timeout when connecting to the remote host.

Defaults to 30 seconds.

Source

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.

Source

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.

Source

pub fn with_connection_age_limit<L>(self, limit: L) -> Self
where L: Into<Option<Duration>>,

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.

Source

pub fn with_max_idle_conns_per_host(self, max: usize) -> Self

Sets the maximum number of idle connections per host.

Defaults to 5.

Source

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.

Source

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).

Source

pub fn with_endpoint_telemetry<F>( self, metrics_builder: MetricsBuilder, endpoint_name_fn: Option<F>, ) -> Self
where F: Fn(&Uri) -> Option<MetaString> + Send + Sync + 'static,

Enables per-endpoint telemetry for HTTP transactions.

See EndpointTelemetryLayer for more information.

Source

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).

Source

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.

Source

pub fn with_hyper_config<F>(self, f: F) -> Self
where F: FnOnce(&mut Builder),

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.

Source

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.

Source

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§

Source§

impl Default for HttpClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Track for T

Source§

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper. Read more
Source§

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more