Skip to main content

ReqwestStreamBody

Struct ReqwestStreamBody 

Source
pub struct ReqwestStreamBody { /* private fields */ }
Available on crate features arrow or csv or json or protobuf only.
Expand description

A request body that streams a sequence of items.

Convert it into a reqwest::Body with .into(), or hand it to StreamBodyRequest::stream_body, which also sets the Content-Type.

§HTTP caveats

Streaming a request body is much less universally supported than streaming a response. None of the following stops it working, but each will surprise you if it is not expected.

  1. The body cannot be replayed. RequestBuilder::try_clone returns None for a streaming body, so retry middleware — reqwest-retry and anything like it — cannot retry the request.
  2. A redirect silently sends an empty body. reqwest follows redirects through a middleware that substitutes a default body when the original cannot be cloned, and for reqwest that default is an empty body. A 307 or 308 on a streaming upload therefore arrives at the new location with nothing in it, and no error is reported. Use redirect::Policy::none for streaming uploads and handle redirects yourself.
  3. Transfer-Encoding is chunked. No Content-Length can be computed, so HTTP/1.1 uses chunked encoding. Some API gateways reject chunked request bodies. HTTP/2 is unaffected.
  4. Expect: 100-continue is not supported. hyper neither sends it nor waits for it, so setting the header by hand does not get you the behaviour: you may upload a great many bytes before learning the request was rejected. When the server does answer early, the body is dropped and the outcome is reported as aborted.
  5. Buffering reverse proxies defeat streaming. nginx buffers request bodies by default (proxy_request_buffering on), as do many CDNs and API gateways; the server then sees one complete body rather than a stream. Set proxy_request_buffering off;.
  6. Timeouts cover the whole exchange. RequestBuilder::timeout spans connect through response body, so a slow source stream can trip it.

Implementations§

Source§

impl ReqwestStreamBody

Source

pub fn new<S, T, FMT>(format: FMT, stream: S) -> Self
where FMT: StreamFormatEncode<T> + StreamFormat, FMT::Encoder: Send + 'static, S: Stream<Item = T> + Send + 'static, T: Send + 'static,

A body encoding stream with format.

Source

pub fn try_new<S, T, FMT, E>(format: FMT, stream: S) -> Self
where FMT: StreamFormatEncode<T> + StreamFormat, FMT::Encoder: Send + 'static, S: Stream<Item = Result<T, E>> + Send + 'static, T: Send + 'static, E: Into<Box<dyn Error + Send + Sync>> + Send + 'static,

A body encoding a fallible stream with format.

Errors from your source stream are forwarded into the body stream, where they abort the request. Use ReqwestStreamBodyOptions::on_error to observe them.

Source

pub fn with_options<S, T, FMT>( format: FMT, stream: S, options: ReqwestStreamBodyOptions, ) -> Self
where FMT: StreamFormatEncode<T> + StreamFormat, FMT::Encoder: Send + 'static, S: Stream<Item = T> + Send + 'static, T: Send + 'static,

A body encoding stream with format, with options.

Source

pub fn try_with_options<S, T, FMT, E>( format: FMT, stream: S, options: ReqwestStreamBodyOptions, ) -> Self
where FMT: StreamFormatEncode<T> + StreamFormat, FMT::Encoder: Send + 'static, S: Stream<Item = Result<T, E>> + Send + 'static, T: Send + 'static, E: Into<Box<dyn Error + Send + Sync>> + Send + 'static,

A body encoding a fallible stream with format, with options.

Source

pub fn content_type(&self) -> &HeaderValue

The Content-Type this body should be sent with.

StreamBodyRequest::stream_body and the per-format methods set it for you; this is for callers building a request by hand.

Source

pub fn into_stream(self) -> BoxStream<'static, StreamBodyResult<Bytes>>

The encoded bytes, for callers who are not sending an HTTP request.

Public on purpose: it makes the body testable without a server, and lets you write the same encoding to a file, a socket, or an object-store SDK.

Trait Implementations§

Source§

impl Debug for ReqwestStreamBody

Source§

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

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

impl From<ReqwestStreamBody> for Body

Source§

fn from(body: ReqwestStreamBody) -> Self

Converts to this type from the input type.

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