StreamingBody

Structin bodyfastly 0.13.1View source
pub struct StreamingBody { /* private fields */ }

A streaming HTTP body that can be written to, or appended to from another body.

The interface to this type is very similar to Body, however it is write-only, and can only be created as a result of calling Response::stream_to_client() or Request::send_async_streaming(), or as part of a CandidateResponse body transformation.

The most efficient way to write the body is through the Write implementation. Writes are buffered, and automatically flushed, but you can call Write::flush() to explicitly flush the buffer and cause a new chunk to be written to the client.

A streaming body will be automatically aborted if it goes out of scope without calling finish().

Methods

fn abandon(self) -> Result<()>

Abandon a streaming body handle, indicating an unsuccessful end of the stream.

Parameters

self: Self

Returns

std::io::Result<()>
fn append(&mut self, other: Body)

Append a body onto the end of this streaming body.

This operation is performed in amortized constant time, and so should always be preferred to reading an entire body and then writing the same contents to another body.

Examples

let mut streaming_body = beresp.stream_to_client();
streaming_body.append(other_body);

Parameters

self: &mut Self
other: Body
fn finish(self) -> Result<()>

Finish writing to a streaming body handle.

Parameters

self: Self

Returns

std::io::Result<()>

Trait implementations

impl From<StreamingBodyHandle> for StreamingBody

fn from(handle: StreamingBodyHandle) -> Self

Parameters

handle: StreamingBodyHandle

Returns

Self

impl StreamingBodyExt for StreamingBody

append_trailer

View source
fn append_trailer(&mut self, name: impl ToHeaderName, value: impl ToHeaderValue)

Parameters

self: &mut Self
name: impl ToHeaderName
value: impl ToHeaderValue

finish_with_trailers

View source
fn finish_with_trailers(self, trailers: &HeaderMap) -> Result<(), Error>

Parameters

self: Self
trailers: &HeaderMap

Returns

Result<(), std::io::Error>

impl Write for StreamingBody

fn flush(&mut self) -> Result<()>

Parameters

self: &mut Self

Returns

std::io::Result<()>
fn write(&mut self, buf: &[u8]) -> Result<usize>

Parameters

self: &mut Self
buf: &[u8]

Returns

std::io::Result<usize>

write_vectored

View source
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>

Parameters

self: &mut Self
bufs: &[std::io::IoSlice]

Returns

std::io::Result<usize>

Auto trait implementations

Blanket implementations