Skip to main content

body_from_stream

Function body_from_stream 

Source
pub fn body_from_stream<S>(stream: S) -> BoxBody
where S: Stream<Item = Result<Frame<Bytes>, BoxBodyError>> + Send + 'static,
Expand description

Create a streaming BoxBody from a Stream of Result<Frame<Bytes>, E>.

Use this for Server-Sent Events, chunked responses, or any streaming body. The stream only needs to be SendSync is not required.

§Example

use futures::stream;
use http_body::Frame;

let chunks = stream::iter(vec![
    Ok(Frame::data(Bytes::from("chunk 1\n"))),
    Ok(Frame::data(Bytes::from("chunk 2\n"))),
]);
let body = body_from_stream(chunks);