Skip to main content

ClientConfig

Struct ClientConfig 

Source
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: usize

Maximum 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, ReqwestBackend delivers every fetch body 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::Decode reports truncation through its truncated field. Error::Api and Error::UnexpectedStatus have no such field, so where they are capped they are capped silently.
  • One path is not capped by it: EventStream’s per-frame decode, which Self::max_stream_frame bounds instead.
§max_stream_frame: usize

Maximum 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

Source

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

Source§

fn clone(&self) -> ClientConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

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

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

impl Default for ClientConfig

Source§

fn default() -> Self

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more