#[non_exhaustive]pub struct HttpClientConfig {Show 13 fields
pub client_cert: Option<Box<Path>>,
pub connect_timeout: Option<Duration>,
pub read_timeout: Option<Duration>,
pub request_timeout: Option<Duration>,
pub pool_idle_timeout: Option<Duration>,
pub pool_max_idle_per_host: usize,
pub verbose: bool,
pub extra_headers: BTreeMap<String, String>,
pub redirect: HttpClientRedirectPolicy,
pub referer: bool,
pub tcp: HttpClientTcpConfig,
pub http2: HttpClientHttp2Config,
pub cb: Option<HttpClientCircuitBreakerConfig>,
/* private fields */
}
Expand description
HTTP client configuration.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.client_cert: Option<Box<Path>>
Path to PEM-formatted file containing a private key and at least one client certificate.
connect_timeout: Option<Duration>
Set a timeout for only the connect phase of a client.
Default is None
.
read_timeout: Option<Duration>
Enables a read timeout.
The timeout applies to each read operation, and resets after a successful read. This is more appropriate for detecting stalled connections when the size isn’t known beforehand.
Default is no timeout.
request_timeout: Option<Duration>
Enables a total request timeout.
The timeout is applied from when the request starts connecting until the response body has finished. Also considered a total deadline.
Default is no timeout.
pool_idle_timeout: Option<Duration>
Set an optional timeout for idle sockets being kept-alive.
Set to None
to disable timeout.
Default is 90 seconds.
pool_max_idle_per_host: usize
Sets the maximum idle connection per host allowed in the pool.
verbose: bool
Set whether connections should emit verbose logs.
Enabling this option will emit log
messages at the TRACE
level for read and write
operations on connections.
extra_headers: BTreeMap<String, String>
Sets the default headers for every request.
redirect: HttpClientRedirectPolicy
Set a redirect policy for this client.
Default will follow redirects up to a maximum of 10.
referer: bool
Enable or disable automatic setting of the Referer
header.
Default is true
.
tcp: HttpClientTcpConfig
TCP-level configuration.
http2: HttpClientHttp2Config
HTTP/2 protocol configuration.
cb: Option<HttpClientCircuitBreakerConfig>
Circuit breaker configuration.
Implementations§
Source§impl HttpClientConfig
impl HttpClientConfig
Sourcepub fn with_app_name(&mut self, app_name: impl ToString) -> &mut Self
pub fn with_app_name(&mut self, app_name: impl ToString) -> &mut Self
Set short name of an application.
Whitespace is not allowed, as this value is used in User-Agent: HTTP header, among other things.
Sourcepub fn with_app_version(&mut self, app_version: impl ToString) -> &mut Self
pub fn with_app_version(&mut self, app_version: impl ToString) -> &mut Self
Set application version.
Preferably in semver format. Whitespace is not allowed, as this value is used in Server: HTTP header, among other things.
Sourcepub async fn to_client_builder(&self) -> Result<ClientBuilder, HttpClientError>
pub async fn to_client_builder(&self) -> Result<ClientBuilder, HttpClientError>
Create reqwest::ClientBuilder
from configuration.
§Errors
Returns Err
if:
- Some client configuration is invalid.
- Unable to load TLS identity file(s) from filesystem.
Sourcepub fn build_client(
&self,
builder: ClientBuilder,
metrics: Option<ClientMetricsState>,
) -> Result<ClientWithMiddleware, HttpClientError>
pub fn build_client( &self, builder: ClientBuilder, metrics: Option<ClientMetricsState>, ) -> Result<ClientWithMiddleware, HttpClientError>
Convert passed client builder into client with all necessary middlewares attached.
§Errors
Returns Err
if:
- TLS subsystem cannot be initialized.
- DNS resolver fails to load its configuration.
Sourcepub async fn to_client(
&self,
metrics: Option<ClientMetricsState>,
) -> Result<ClientWithMiddleware, HttpClientError>
pub async fn to_client( &self, metrics: Option<ClientMetricsState>, ) -> Result<ClientWithMiddleware, HttpClientError>
Trait Implementations§
Source§impl Clone for HttpClientConfig
impl Clone for HttpClientConfig
Source§fn clone(&self) -> HttpClientConfig
fn clone(&self) -> HttpClientConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for HttpClientConfig
impl Debug for HttpClientConfig
Source§impl Default for HttpClientConfig
impl Default for HttpClientConfig
Source§impl<'de> Deserialize<'de> for HttpClientConfig
impl<'de> Deserialize<'de> for HttpClientConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for HttpClientConfig
impl PartialEq for HttpClientConfig
Source§impl Serialize for HttpClientConfig
impl Serialize for HttpClientConfig
impl StructuralPartialEq for HttpClientConfig
Auto Trait Implementations§
impl Freeze for HttpClientConfig
impl RefUnwindSafe for HttpClientConfig
impl Send for HttpClientConfig
impl Sync for HttpClientConfig
impl Unpin for HttpClientConfig
impl UnwindSafe for HttpClientConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> 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::Request
Source§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::Request
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> StateClone for T
impl<T> StateClone for T
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.