pub struct TransportConfig {
pub pool_max_idle_per_host: usize,
pub pool_idle_timeout: Option<Duration>,
pub tcp_keepalive: Option<Duration>,
pub http2_prior_knowledge: bool,
pub dns_cache_ttl: Option<Duration>,
pub disable_proxies: bool,
}Expand description
HTTP transport configuration for reqwest::Client.
Manages connection pooling, DNS caching, TLS session resumption, and HTTP version negotiation. All fields have defaults that preserve the current behavior and do not require explicit configuration.
Fields§
§pool_max_idle_per_host: usizeMaximum number of idle connections per host in the connection pool.
Default: 32. Set to 0 to disable pooling.
pool_idle_timeout: Option<Duration>How long an idle connection remains in the pool before being dropped.
Default: 90 seconds. Set to None to disable idle timeout.
tcp_keepalive: Option<Duration>TCP keepalive interval for idle connections.
Default: 60 seconds. Set to None to disable.
Helps detect stale connections on long-lived clients.
http2_prior_knowledge: boolEnable HTTP/2 prior-knowledge.
When true, the client assumes the server supports HTTP/2 and skips the ALPN negotiation for HTTP/1.1 fallback. Saves a round-trip for endpoints that advertise HTTP/2 support (OpenAI, Anthropic).
Default: false (disable to avoid breaking custom base URLs).
dns_cache_ttl: Option<Duration>DNS cache time-to-live.
Default: 30 seconds. DNS lookups are cached locally for this duration
before re-resolving. Set to None to disable the local DNS cache and
always re-resolve on each request.
disable_proxies: boolIgnore ambient proxy settings (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY
and the system proxy configuration).
Any active outbound policy already disables proxies, so the guarded
resolver sees every upstream host. Set this to rule out a machine-level
proxy as a credential exposure path when the outbound policy is Off,
without changing the process environment.
Redirects need no switch: the authenticated client never follows them, so credentials and request bodies cannot be forwarded to another origin.
Default: false.
Implementations§
Source§impl TransportConfig
impl TransportConfig
Sourcepub fn with_pool_max_idle_per_host(self, count: usize) -> Self
pub fn with_pool_max_idle_per_host(self, count: usize) -> Self
Set the maximum idle connections per host.
Sourcepub fn with_pool_idle_timeout(self, timeout: Option<Duration>) -> Self
pub fn with_pool_idle_timeout(self, timeout: Option<Duration>) -> Self
Set the idle connection timeout.
Sourcepub fn with_tcp_keepalive(self, interval: Option<Duration>) -> Self
pub fn with_tcp_keepalive(self, interval: Option<Duration>) -> Self
Set the TCP keepalive interval.
Sourcepub fn with_http2_prior_knowledge(self, enabled: bool) -> Self
pub fn with_http2_prior_knowledge(self, enabled: bool) -> Self
Enable or disable HTTP/2 prior-knowledge.
Sourcepub fn with_dns_cache_ttl(self, ttl: Option<Duration>) -> Self
pub fn with_dns_cache_ttl(self, ttl: Option<Duration>) -> Self
Set the DNS cache TTL.
Sourcepub fn with_proxies_disabled(self, disabled: bool) -> Self
pub fn with_proxies_disabled(self, disabled: bool) -> Self
Ignore (or honor) ambient proxy settings from the environment.
Sourcepub fn apply_to_builder(&self, builder: ClientBuilder) -> ClientBuilder
pub fn apply_to_builder(&self, builder: ClientBuilder) -> ClientBuilder
Apply all transport settings to a reqwest::ClientBuilder.
This method converts transport fields into concrete reqwest builder calls. Call it once during client construction and chain the returned builder.
Not available on WASM targets: the browser fetch API controls transport settings and does not expose builder-level hooks.
§Fields and their reqwest mapping
| Field | reqwest method |
|---|---|
pool_max_idle_per_host | .pool_max_idle_per_host(n) |
pool_idle_timeout | .pool_idle_timeout(t) |
tcp_keepalive | .tcp_keepalive(t) |
http2_prior_knowledge | .http2_prior_knowledge() (when true) |
dns_cache_ttl | .dns_resolver(...) during native client construction |
enable_http3 | .http3_prior_knowledge() (when true and http3 feature is on) |
disable_proxies | .no_proxy() (when true) |
§DNS TTL
reqwest 0.13 exposes DNS customization through ClientBuilder::dns_resolver
rather than a direct TTL setter. The native client construction path
installs a resolver that combines this TTL with outbound-policy DNS
validation, so DNS rebinding protection is preserved when both features
are active.