pub struct Timeout {
pub pool: Option<Duration>,
pub connect: Option<Duration>,
pub write: Option<Duration>,
pub read: Option<Duration>,
pub total: Option<Duration>,
}Expand description
Phase-aware timeout configuration for a request.
Each field is optional. When None, the corresponding phase has no
timeout. When a field is Some(duration), the phase will fail with
crate::Error::Timeout if it exceeds the given duration.
§Enforcement
pool: enforced viatokio::time::timeoutaround the pool acquire.read: on Hyper/UDS routes, response-header waiting is bounded after request-body completion; response-body progress is enforced per chunk by a wrapper stream and resets on each arrival. Experimental HTTP/3 currently applies this field to response-body chunks only.write: enforced per chunk by a wrapper stream that firesError::Timeout { phase: Write }when the request body producer does not yield a chunk within the configured duration. Resets on every chunk delivery. Only applies to streamed request bodies; buffered bodies complete synchronously.total: absolute wall-clock deadline from logical request start through response-body EOF/trailers. Enforced around the transport future and retained on the response body; never restarted per chunk, decode selection, redirect hop, retry attempt, or first body poll.connect: enforced by wrapping the underlying connector with a timeout that bounds DNS resolution, TCP connect, and TLS handshake. FiresError::Timeout { phase: Connect }if the connection is not established within the configured duration.
§Default
The default Timeout has all phases disabled (all None).
§Examples
use std::time::Duration;
use eggfetch_core::Timeout;
// All phases get 5 seconds.
let t = Timeout::from_secs(5);
// Only read and total are configured.
let t = Timeout {
read: Some(Duration::from_secs(30)),
total: Some(Duration::from_secs(60)),
..Timeout::default()
};Fields§
§pool: Option<Duration>Time allowed to wait for a connection slot from the pool.
connect: Option<Duration>Time allowed to establish TCP connection and TLS handshake. Includes DNS resolution when performed as part of connect. Enforced by wrapping the underlying connector with a deadline.
write: Option<Duration>Time allowed for the request body producer to yield each frame.
Applies to high-level streamed request bodies and the native
http_body::Body execution surface.
read: Option<Duration>Time allowed for response headers after request-body completion and between response-body chunks. The body timer starts on first body poll and resets on every chunk. Experimental HTTP/3 currently applies this field to response-body progress only.
total: Option<Duration>Optional wall-clock cap across the entire request lifecycle.
Implementations§
Source§impl Timeout
impl Timeout
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
Create a timeout with all phases disabled.
This is the same as Timeout::default().
Sourcepub fn from_secs(secs: u64) -> Self
pub fn from_secs(secs: u64) -> Self
Create a timeout where pool, connect, write, and read each get the given duration.
The total timeout is not set. Use Timeout::builder or the
struct literal syntax to set it explicitly.
§Examples
use eggfetch_core::Timeout;
let t = Timeout::from_secs(5);
assert_eq!(t.pool, Some(std::time::Duration::from_secs(5)));
assert_eq!(t.connect, Some(std::time::Duration::from_secs(5)));
assert_eq!(t.write, Some(std::time::Duration::from_secs(5)));
assert_eq!(t.read, Some(std::time::Duration::from_secs(5)));
assert!(t.total.is_none());Sourcepub fn compat() -> Self
pub fn compat() -> Self
Create an HTTPX-compatible timeout configuration.
HTTPX 0.28.1 uses 5 seconds for each operational phase. It does not
define a request-wide wall-clock timeout, so total remains unset.
Set total explicitly when an EggFetch-native outer deadline is
desired.
§Examples
use std::time::Duration;
use eggfetch_core::Timeout;
let t = Timeout::compat();
assert_eq!(t.pool, Some(Duration::from_secs(5)));
assert_eq!(t.connect, Some(Duration::from_secs(5)));
assert_eq!(t.write, Some(Duration::from_secs(5)));
assert_eq!(t.read, Some(Duration::from_secs(5)));
assert!(t.total.is_none());Sourcepub fn native() -> Self
pub fn native() -> Self
Create eggfetch-native timeout defaults.
Uses 30 seconds for pool, connect, write, and read phases with no total timeout. This is appropriate for general-purpose use where the caller controls overall deadlines.
§Examples
use std::time::Duration;
use eggfetch_core::Timeout;
let t = Timeout::native();
assert_eq!(t.pool, Some(Duration::from_secs(30)));
assert_eq!(t.connect, Some(Duration::from_secs(30)));
assert_eq!(t.write, Some(Duration::from_secs(30)));
assert_eq!(t.read, Some(Duration::from_secs(30)));
assert!(t.total.is_none());Sourcepub fn builder() -> TimeoutBuilder
pub fn builder() -> TimeoutBuilder
Create a TimeoutBuilder for configuring individual phases.