pub struct ReqwestStreamBody { /* private fields */ }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.
- The body cannot be replayed.
RequestBuilder::try_clonereturnsNonefor a streaming body, so retry middleware —reqwest-retryand anything like it — cannot retry the request. - A redirect silently sends an empty body.
reqwestfollows redirects through a middleware that substitutes a default body when the original cannot be cloned, and forreqwestthat 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. Useredirect::Policy::nonefor streaming uploads and handle redirects yourself. - Transfer-Encoding is chunked. No
Content-Lengthcan be computed, so HTTP/1.1 uses chunked encoding. Some API gateways reject chunked request bodies. HTTP/2 is unaffected. Expect: 100-continueis 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 asaborted.- 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. Setproxy_request_buffering off;. - Timeouts cover the whole exchange.
RequestBuilder::timeoutspans connect through response body, so a slow source stream can trip it.
Implementations§
Source§impl ReqwestStreamBody
impl ReqwestStreamBody
Sourcepub fn new<S, T, FMT>(format: FMT, stream: S) -> Selfwhere
FMT: StreamFormatEncode<T> + StreamFormat,
FMT::Encoder: Send + 'static,
S: Stream<Item = T> + Send + 'static,
T: Send + 'static,
pub fn new<S, T, FMT>(format: FMT, stream: S) -> Selfwhere
FMT: StreamFormatEncode<T> + StreamFormat,
FMT::Encoder: Send + 'static,
S: Stream<Item = T> + Send + 'static,
T: Send + 'static,
A body encoding stream with format.
Sourcepub fn try_new<S, T, FMT, E>(format: FMT, stream: S) -> Self
pub fn try_new<S, T, FMT, E>(format: FMT, stream: S) -> Self
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.
Sourcepub fn with_options<S, T, FMT>(
format: FMT,
stream: S,
options: ReqwestStreamBodyOptions,
) -> Selfwhere
FMT: StreamFormatEncode<T> + StreamFormat,
FMT::Encoder: Send + 'static,
S: Stream<Item = T> + Send + 'static,
T: Send + 'static,
pub fn with_options<S, T, FMT>(
format: FMT,
stream: S,
options: ReqwestStreamBodyOptions,
) -> Selfwhere
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.
Sourcepub fn try_with_options<S, T, FMT, E>(
format: FMT,
stream: S,
options: ReqwestStreamBodyOptions,
) -> Self
pub fn try_with_options<S, T, FMT, E>( format: FMT, stream: S, options: ReqwestStreamBodyOptions, ) -> Self
A body encoding a fallible stream with format, with options.
Sourcepub fn content_type(&self) -> &HeaderValue
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.
Sourcepub fn into_stream(self) -> BoxStream<'static, StreamBodyResult<Bytes>>
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.