pub struct ClientConfig {
pub timeout: Option<Duration>,
pub connect_timeout: Option<Duration>,
pub retry_policy: RetryPolicy,
pub request_interceptors: Vec<RequestInterceptor>,
pub response_interceptors: Vec<ResponseInterceptor>,
pub default_headers: HeaderMap,
pub cookie_store: bool,
pub enable_tracing: bool,
}Expand description
Configuration for the Client.
Controls per-request timeouts, TCP connect timeouts, retry behavior, request/response interceptors, default headers, and cookie persistence.
§Example
use typeway_client::{ClientConfig, RetryPolicy, RequestInterceptor};
use std::sync::Arc;
use std::time::Duration;
let config = ClientConfig::default()
.timeout(Duration::from_secs(60))
.retry_policy(RetryPolicy::none())
.bearer_auth("my-token")
.cookie_store(true)
.request_interceptor(Arc::new(|req| {
req.header("X-Request-Id", "abc123")
}));Fields§
§timeout: Option<Duration>Per-request timeout. None means no timeout.
connect_timeout: Option<Duration>TCP connection timeout. None means no timeout.
retry_policy: RetryPolicyRetry policy for failed requests.
request_interceptors: Vec<RequestInterceptor>Interceptors applied to every outgoing request.
response_interceptors: Vec<ResponseInterceptor>Interceptors called on every incoming response.
default_headers: HeaderMapHeaders sent with every request.
Whether to enable automatic cookie persistence across requests.
enable_tracing: boolWhether to enable built-in request/response tracing via the tracing crate.
When enabled, every request logs the HTTP method, URL, response status,
and elapsed time at DEBUG level.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn no_timeout(self) -> Self
pub fn no_timeout(self) -> Self
Disable the per-request timeout.
Sourcepub fn connect_timeout(self, d: Duration) -> Self
pub fn connect_timeout(self, d: Duration) -> Self
Set the TCP connect timeout.
Sourcepub fn no_connect_timeout(self) -> Self
pub fn no_connect_timeout(self) -> Self
Disable the TCP connect timeout.
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Set the retry policy.
Sourcepub fn request_interceptor(self, interceptor: RequestInterceptor) -> Self
pub fn request_interceptor(self, interceptor: RequestInterceptor) -> Self
Add a request interceptor that modifies outgoing requests.
Interceptors are applied in the order they are added.
§Example
use typeway_client::{ClientConfig, RequestInterceptor};
use std::sync::Arc;
let config = ClientConfig::default()
.request_interceptor(Arc::new(|req| {
req.header("X-Trace-Id", "abc")
}));Sourcepub fn response_interceptor(self, interceptor: ResponseInterceptor) -> Self
pub fn response_interceptor(self, interceptor: ResponseInterceptor) -> Self
Add a response interceptor that inspects incoming responses.
Interceptors are called in the order they are added.
§Example
use typeway_client::{ClientConfig, ResponseInterceptor};
use std::sync::Arc;
let config = ClientConfig::default()
.response_interceptor(Arc::new(|resp| {
eprintln!("status: {}", resp.status());
}));Sourcepub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self
Add a default header sent with every request.
§Panics
Panics if name or value cannot be parsed as valid HTTP header
components.
Sourcepub fn bearer_auth(self, token: &str) -> Self
pub fn bearer_auth(self, token: &str) -> Self
Convenience method to set a Bearer authentication token.
This adds an Authorization: Bearer <token> header to every request.
Enable or disable automatic cookie persistence across requests.
When enabled, the underlying HTTP client stores cookies from responses and sends them back in subsequent requests, providing session-like behavior.
Sourcepub fn enable_tracing(self) -> Self
pub fn enable_tracing(self) -> Self
Enable built-in request/response tracing.
When enabled, every HTTP request logs the method, URL, response status,
and elapsed time at DEBUG level via the tracing crate.