packages

http::body

On this page

Message bodies: a stream of byte chunks over a channel.

Structs

BodySource

pub struct Body

A message body: a stream of byte chunks read once with chunk, bytes or text. A body built from bytes also keeps them, so a request with one can be resent (redirects). A body has one owner: let b = a, storing it or capturing it moves it.

  • pub fn empty() -> Body§

    Source
  • pub fn from_bytes(data: List<u8>) -> Body§

    Source
  • pub fn from_str(s: str) -> Body§

    Source
  • pub fn channel(cap: usize = 4, len: u64 | none = none) -> (BodyWriter, Body)§

    Source

    A body fed by the returned writer, with room for cap chunks in flight. len: the total, if known in advance.

  • pub fn len(self) -> u64 | none§

    Source

    The length, if known.

  • pub fn is_empty(self) -> bool§

    Source

    Whether the body is known to be empty.

  • pub fn replayable(self) -> List<u8> | none§

    Source

    The bytes it was built from, if it was.

  • pub async fn chunk(self) throws (HttpError) -> List<u8> | none§

    Source

    The next chunk, or none at the end.

  • pub async fn bytes(self, limit: usize = 1usize << 30usize) throws (HttpError) -> List<u8>§

    Source

    The whole body; throws TooLarge past limit bytes.

  • pub async fn text(self, limit: usize = 1usize << 30usize) throws (HttpError) -> str§

    Source

    The whole body as UTF-8 text.

BodyWriterSource

pub struct BodyWriter

The feeding end of Body::channel.

  • pub async fn send(self, data: List<u8>) throws (HttpError)§

    Source

    Send a chunk; waits while cap chunks are unread. Throws Closed when the reader is gone.

  • pub async fn send_str(self, s: str) throws (HttpError)§

    Source
  • pub fn finish(self)§

    Source

    End the body.

  • pub async fn fail(self, e: HttpError)§

    Source

    End the body with an error the reader gets.