pub struct StreamBody { /* private fields */ }Expand description
A streaming response body: downloads, CSV exports, anything produced
incrementally. Defaults: application/octet-stream, 200 OK, 30s frame
timeout (a producer that stalls longer aborts the connection).
Implementations§
Source§impl StreamBody
impl StreamBody
Sourcepub const DEFAULT_FRAME_TIMEOUT: Duration
pub const DEFAULT_FRAME_TIMEOUT: Duration
Default per-frame producer deadline (see StreamBody::frame_timeout).
Sourcepub fn new<S>(stream: S) -> Self
pub fn new<S>(stream: S) -> Self
Stream chunks from anything implementing Stream (SeaORM streaming
queries, hand-rolled producers). An Err item aborts the connection.
Sourcepub fn channel() -> (Self, BodySender)
pub fn channel() -> (Self, BodySender)
A channel-fed body for producers that push: returns the body and a
sender. Dropping the sender ends the stream cleanly; fail aborts it.
The channel is bounded, so send awaits while a slow client is behind.
Sourcepub fn content_type(self, value: &str) -> Self
pub fn content_type(self, value: &str) -> Self
Sets the content-type header. Panics on a value that is not a valid
header value — that is a programming error, not request-dependent.
Sourcepub fn attachment(self, filename: &str) -> Self
pub fn attachment(self, filename: &str) -> Self
Marks the response as a download: content-disposition: attachment with
the given filename. Quotes/backslashes are stripped (header-injection
break-out) and control chars too — stripping the latter is what makes the
following HeaderValue::from_str infallible for any UTF-8 input. Non-ASCII
filenames pass through verbatim (no RFC 5987 filename* encoding).
Sourcepub fn frame_timeout(self, timeout: Duration) -> Self
pub fn frame_timeout(self, timeout: Duration) -> Self
Maximum time the producer may take between chunks before the connection is aborted.