pub struct ClientConfig {
pub max_error_body: usize,
pub max_stream_frame: usize,
pub timeout: Option<Duration>,
pub max_success_body: Option<usize>,
}Expand description
Client-wide configuration.
Fields§
§max_error_body: usizeMaximum bytes of a response body retained on error variants; the rest is dropped (default 64 KiB).
Where it applies, and what says so:
- Bodies read as errors are capped, and on native targets the cap bounds reading too —
an over-cap body is abandoned partway, which forgoes reuse of that connection. On
wasm32,ReqwestBackenddelivers everyfetchbody whole, an error body of a streaming operation included, so there only retention is guaranteed to be bounded. - A success body that fails to decode is capped on retention only. Deserialization needs the whole body, so it is always read whole.
Error::Decodereports truncation through itstruncatedfield.Error::ApiandError::UnexpectedStatushave no such field, so where they are capped they are capped silently.- One path is not capped by it:
EventStream’s per-frame decode, whichSelf::max_stream_framebounds instead.
max_stream_frame: usizeMaximum bytes EventStream buffers for one item whose terminator has not arrived yet
(default 16 MiB): an SSE event before its blank line, an ndjson line before its newline, a
JSON text sequence record before the next separator.
Once more than this many bytes of such an item are buffered, the stream yields
Error::Decode retaining at most max_error_body bytes of them, with truncated set,
and then ends, without consulting a reconnect policy. Complete items read in the same
chunk ahead of the over-limit one are yielded first. Bytes arrive a chunk at a time, so the
buffer may hold up to one chunk more than this limit before the check runs, and an item
whose terminator arrives in the same chunk that takes it past the limit is framed
normally.
It also bounds what a per-frame decode failure retains: an item within the limit that
fails to decode is reported as Error::Decode retaining the whole frame, uncapped by
max_error_body, with truncated unset.
timeout: Option<Duration>How long one non-streaming request may take in total, from connecting until its whole
response body has been read, before it fails with Error::Timeout (default None: no
total bound, only the connect and read timeouts).
It is read each time the runtime’s send sends a request, so changing it through
ClientCore::config_mut applies from the next request on, whichever constructor built
the core, and it is honoured on wasm32 too. A generated client’s with_timeout sets it
on the client value it returns, which is how one call gets a deadline of its own. It
travels on the request itself, as a super::TotalTimeout extension: a request that
already carries one keeps it, as does one given one by RequestOptions::extensions,
which send applies first, ReqwestBackend enforces it, and so does a caller-supplied
HttpBackend that delegates to a ReqwestBackend or reads the extension itself. Behind
a super::RetryBackend it bounds each attempt, not the retried call as a whole. A call
replayed after a refreshable credential was rejected and refreshed sends the replay with a
TotalTimeout of its own, so the call as a whole may take this long for the first
exchange, the refresh as long as it takes, and this long again for the replay. A
streaming response is exempt,
because a stream may rightly stay open indefinitely: an operation returning an
EventStream sends its request with the runtime’s send_streaming, which never applies
it, and each reconnect is sent the same way.
max_success_body: Option<usize>Maximum bytes of a success body a non-streaming operation reads before it fails with
Error::BodyTooLarge (default None: a structured success body is read whole, however
large, and a raw binary one up to Self::DEFAULT_MAX_BINARY_BODY).
A response whose Content-Length declares more is refused before any of its body is read,
and one that grows past it is abandoned at the chunk that crosses it, which forgoes reuse
of that connection; peak memory is the limit, not what the server chose to send. The
answer to a HEAD request and a 1xx, 204 or 304 response carry no body, so their
Content-Length, which describes a representation they do not carry, refuses nothing;
whatever body they do carry is bounded as it is read.
RequestOptions::max_body, set per client value with a generated client’s
with_options, replaces it. It is read each time the runtime’s send sends a request, as
Self::timeout is. An operation returning an EventStream is exempt: its items are
bounded by Self::max_stream_frame instead. So is each raw binary body a _stream twin
returns as a super::ByteStream, whose reader picks its own limit; any other success body
the twin of a success enum reads is read within this one.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub const DEFAULT_MAX_BINARY_BODY: usize
pub const DEFAULT_MAX_BINARY_BODY: usize
The most bytes a raw binary success body (application/octet-stream, image/*, …) read
whole is allowed to hold where neither RequestOptions::max_body nor
Self::max_success_body sets a limit: 64 MiB. Either of those replaces it, larger or
smaller; a body past it fails with Error::BodyTooLarge. Every operation whose success
holds a raw binary body, as its one success body or as a status of its success enum, has a
_stream twin, which hands that body over unread as a super::ByteStream instead: a
download this limit would refuse is read through it.
Trait Implementations§
Source§impl Clone for ClientConfig
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClientConfig
impl Debug for ClientConfig
Auto Trait Implementations§
impl Freeze for ClientConfig
impl RefUnwindSafe for ClientConfig
impl Send for ClientConfig
impl Sync for ClientConfig
impl Unpin for ClientConfig
impl UnsafeUnpin for ClientConfig
impl UnwindSafe for ClientConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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