#[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>,
}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
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
impl ReqwestStreamBodyOptions
Sourcepub fn content_type(self, content_type: HeaderValue) -> Self
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_bodymethods sends twoContent-Typeheaders. - 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.
Sourcepub fn buffering_bytes(self, size: usize) -> Self
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.
Sourcepub fn buffering_ready_items(self, count: usize) -> Self
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.
Sourcepub fn on_error<F>(self, handler: F) -> Self
pub fn on_error<F>(self, handler: F) -> Self
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.
Sourcepub fn on_progress<F>(self, handler: F) -> Self
pub fn on_progress<F>(self, handler: F) -> Self
Registers a callback receiving progress snapshots as the body is uploaded.
Sourcepub fn progress_interval(self, interval: Duration) -> Self
pub fn progress_interval(self, interval: Duration) -> Self
Reports progress at most once per interval.
Sourcepub fn progress_items(self, items: u64) -> Self
pub fn progress_items(self, items: u64) -> Self
Additionally reports progress every items items.