Skip to main content

ReqwestStreamBodyOptions

Struct ReqwestStreamBodyOptions 

Source
#[non_exhaustive]
pub struct ReqwestStreamBodyOptions { pub content_type: Option<HeaderValue>, pub buffering_bytes: Option<usize>, pub buffering_ready_items: Option<usize>, pub on_error: Option<ReqwestStreamErrorHandler>, pub on_progress: Option<ReqwestStreamProgressHandler>, pub progress_interval: Option<Duration>, pub progress_items: Option<u64>, }
Available on crate features arrow or csv or json or protobuf only.
Expand description

Options for a streamed request body.

Separate from ReqwestStreamOptions on purpose: that one carries max_obj_len and buf_capacity, which are decode-side concepts — a guard against a hostile peer, and the size of a read buffer. Neither means anything when you are the one producing the bytes.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§content_type: Option<HeaderValue>

Overrides the Content-Type the format would otherwise set.

§buffering_bytes: Option<usize>

Coalesce output into chunks of at least this many bytes.

§buffering_ready_items: Option<usize>

Coalesce every N items that are ready together into one chunk.

§on_error: Option<ReqwestStreamErrorHandler>

Invoked for every error produced while encoding the body.

§on_progress: Option<ReqwestStreamProgressHandler>

Invoked for every progress report.

§progress_interval: Option<Duration>

How often to report interim progress. One second by default.

§progress_items: Option<u64>

Additionally report progress every N items.

Implementations§

Source§

impl ReqwestStreamBodyOptions

Source

pub fn new() -> Self

Default options.

Source

pub fn content_type(self, content_type: HeaderValue) -> Self

Sets the Content-Type.

This is the only reliable way to override it, because RequestBuilder::header appends rather than replaces:

  • Chaining .header(CONTENT_TYPE, …) after one of the *_stream_body methods sends two Content-Type headers.
  • Chaining it once before is replaced, which is what you would want.
  • Chaining it twice before leaves the second value in place, because replacement overwrites only the first value for a name. The request then carries two after all.
Source

pub fn buffering_bytes(self, size: usize) -> Self

Coalesce output into chunks of at least size bytes.

Worth setting for formats whose items are small: without it, JSON Lines of short objects emits one chunked-transfer frame per item.

Ignored if buffering_ready_items is also set; the two are alternatives and the item-based one wins.

Source

pub fn buffering_ready_items(self, count: usize) -> Self

Coalesce every count items that are ready together into one chunk.

Takes precedence over buffering_bytes if both are set.

Source

pub fn on_error<F>(self, handler: F) -> Self
where F: Fn(&StreamBodyError) + Send + Sync + 'static,

Registers a callback invoked for every error produced while encoding the body.

Worth more here than on the response side. When a request body errors, hyper aborts the request and send returns a generic transport error with the original cause usually flattened away — so this is often the only way to find out what failed.

Source

pub fn on_progress<F>(self, handler: F) -> Self
where F: Fn(&ReqwestStreamProgress) + Send + Sync + 'static,

Registers a callback receiving progress snapshots as the body is uploaded.

Source

pub fn progress_interval(self, interval: Duration) -> Self

Reports progress at most once per interval.

Source

pub fn progress_items(self, items: u64) -> Self

Additionally reports progress every items items.

Trait Implementations§

Source§

impl Default for ReqwestStreamBodyOptions

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

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

Source§

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

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> PolicyExt for T
where T: ?Sized,

Source§

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

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

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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