Skip to main content

StreamBody

Struct StreamBody 

Source
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

Source

pub const DEFAULT_FRAME_TIMEOUT: Duration

Default per-frame producer deadline (see StreamBody::frame_timeout).

Source

pub fn new<S>(stream: S) -> Self
where S: Stream<Item = Result<Bytes, Error>> + Send + Sync + 'static,

Stream chunks from anything implementing Stream (SeaORM streaming queries, hand-rolled producers). An Err item aborts the connection.

Source

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.

Source

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.

Source

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).

Source

pub fn frame_timeout(self, timeout: Duration) -> Self

Maximum time the producer may take between chunks before the connection is aborted.

Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.