pub struct Timeouts {
pub connect: Option<Duration>,
pub ttfb: Option<Duration>,
pub read_idle: Option<Duration>,
pub write_idle: Option<Duration>,
pub total: Option<Duration>,
pub pool_acquire: Option<Duration>,
}Expand description
Timeout configuration for HTTP requests.
All timeouts are optional. When None, no timeout is applied for that phase.
§Timeout Semantics
- connect: Does NOT reset. Deadline for establishing transport connection.
- ttfb: Does NOT reset. Deadline from request sent to headers received.
- read_idle: RESETS on each chunk received. Detects hung streams.
- write_idle: RESETS on each chunk sent. Detects hung uploads.
- total: Does NOT reset. Absolute deadline for entire request.
- pool_acquire: Does NOT reset. Time waiting for pooled connection.
Fields§
§connect: Option<Duration>Timeout for establishing connection (DNS + TCP + TLS/QUIC handshake).
Default: 10s for api_defaults(), 10s for streaming_defaults()
ttfb: Option<Duration>Time-to-first-byte timeout: time from request sent until response headers received.
This is the “server responsiveness” timeout - detects servers that accept connections but hang before responding.
Default: 30s for api_defaults(), 30s for streaming_defaults()
read_idle: Option<Duration>Read idle timeout: maximum time waiting for next chunk of response body.
This timeout resets on each successful read. It detects hung streams without killing healthy long-running transfers.
For SSE/streaming, this is typically your primary timeout mechanism.
Default: 30s for api_defaults(), 120s for streaming_defaults()
write_idle: Option<Duration>Write idle timeout: maximum time waiting to send next chunk of request body.
This timeout resets on each successful write. Useful for large uploads.
Default: 30s for both presets
total: Option<Duration>Total request deadline: absolute time limit for entire request lifecycle.
This timeout does NOT reset. It caps connect + request + response.
For streaming responses, you typically want this disabled (None) and rely on read_idle instead.
Default: 120s for api_defaults(), None for streaming_defaults()
pool_acquire: Option<Duration>Pool acquire timeout: time waiting for an available pooled connection.
Under high load, this prevents requests from queueing indefinitely.
Default: 5s for both presets
Implementations§
Source§impl Timeouts
impl Timeouts
Sourcepub fn api_defaults() -> Self
pub fn api_defaults() -> Self
Sensible defaults for normal API calls.
- connect: 10s
- ttfb: 30s
- read_idle: 30s
- write_idle: 30s
- total: 120s
- pool_acquire: 5s
Sourcepub fn streaming_defaults() -> Self
pub fn streaming_defaults() -> Self
Sensible defaults for streaming responses (SSE, chunked downloads, etc.).
Key differences from api_defaults():
-
total: None (streams can run indefinitely)
-
read_idle: 120s (longer to accommodate variable chunk timing)
-
connect: 10s
-
ttfb: 30s
-
read_idle: 120s
-
write_idle: 30s
-
total: None
-
pool_acquire: 5s
Sourcepub fn write_idle(self, timeout: Duration) -> Self
pub fn write_idle(self, timeout: Duration) -> Self
Set write idle timeout.
Sourcepub fn pool_acquire(self, timeout: Duration) -> Self
pub fn pool_acquire(self, timeout: Duration) -> Self
Set pool acquire timeout.
Sourcepub fn no_connect_timeout(self) -> Self
pub fn no_connect_timeout(self) -> Self
Disable connect timeout.
Sourcepub fn no_ttfb_timeout(self) -> Self
pub fn no_ttfb_timeout(self) -> Self
Disable TTFB timeout.
Sourcepub fn no_read_idle_timeout(self) -> Self
pub fn no_read_idle_timeout(self) -> Self
Disable read idle timeout.
Sourcepub fn no_write_idle_timeout(self) -> Self
pub fn no_write_idle_timeout(self) -> Self
Disable write idle timeout.
Sourcepub fn no_total_timeout(self) -> Self
pub fn no_total_timeout(self) -> Self
Disable total timeout.
Sourcepub fn no_pool_acquire_timeout(self) -> Self
pub fn no_pool_acquire_timeout(self) -> Self
Disable pool acquire timeout.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Timeouts
impl RefUnwindSafe for Timeouts
impl Send for Timeouts
impl Sync for Timeouts
impl Unpin for Timeouts
impl UnsafeUnpin for Timeouts
impl UnwindSafe for Timeouts
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> 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 more