Skip to main content

Timeouts

Struct Timeouts 

Source
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

Source

pub fn new() -> Self

Create a new Timeouts with all timeouts set to None.

Source

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
Source

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

Source

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

Set connect timeout.

Source

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

Set TTFB (time-to-first-byte) timeout.

Source

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

Set read idle timeout.

Source

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

Set write idle timeout.

Source

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

Set total request deadline.

Source

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

Set pool acquire timeout.

Source

pub fn no_connect_timeout(self) -> Self

Disable connect timeout.

Source

pub fn no_ttfb_timeout(self) -> Self

Disable TTFB timeout.

Source

pub fn no_read_idle_timeout(self) -> Self

Disable read idle timeout.

Source

pub fn no_write_idle_timeout(self) -> Self

Disable write idle timeout.

Source

pub fn no_total_timeout(self) -> Self

Disable total timeout.

Source

pub fn no_pool_acquire_timeout(self) -> Self

Disable pool acquire timeout.

Trait Implementations§

Source§

impl Clone for Timeouts

Source§

fn clone(&self) -> Timeouts

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Timeouts

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Timeouts

Source§

fn default() -> Timeouts

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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