pub struct ReceivedBody<'conn, Transport> { /* private fields */ }
Expand description

A received http body

This type represents a body that will be read from the underlying transport, which it may either borrow from a Conn or own.

let mut conn = Conn::new_synthetic(Method::Get, "/", "hello");
let body = conn.request_body().await;
assert_eq!(body.read_string().await?, "hello");

Implementations

Returns the content-length of this body, if available. This usually is derived from the content-length header. If the http request or response that this body is attached to uses transfer-encoding chunked, this will be None.

let mut conn = Conn::new_synthetic(Method::Get, "/", "hello");
let body = conn.request_body().await;
assert_eq!(body.content_length(), Some(5));

Reads the entire body to string, using the encoding determined by the content-type (mime) charset. If an encoding problem is encountered, the String returned by read_string will contain utf8 replacement characters.

Note that this can only be performed once per Conn, as the underlying data is not cached anywhere. This is the only copy of the body contents.

Errors

This will return an error if there is an IO error on the underlying transport such as a disconnect

Similar to ReceivedBody::read_string, but returns the raw bytes. This is useful for bodies that are not text.

You can use this in conjunction with encoding if you need different handling of malformed character encoding than the lossy conversion provided by read_string.

Errors

This will return an error if there is an IO error on the underlying transport such as a disconnect

returns the character encoding of this body, usually determined from the content type (mime-type) of the associated Conn.

Consumes the remainder of this body from the underlying transport by reading it to the end and discarding the contents. This is important for http1.1 keepalive, but most of the time you do not need to directly call this. It returns the number of bytes consumed.

Errors

This will return an std::io::Result::Err if there is an io error on the underlying transport, such as a disconnect

takes the static transport from this received body

Trait Implementations

Attempt to read from the AsyncRead into buf. Read more
Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Values yielded by the stream.
Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Reads some bytes from the byte stream. Read more
Like [read()][AsyncReadExt::read()], except it reads into a slice of buffers. Read more
Reads the entire contents and appends them to a Vec. Read more
Reads the entire contents and appends them to a String. Read more
Reads the exact number of bytes required to fill buf. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Converts this [AsyncRead] into a [Stream] of bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

A convenience for calling [Stream::poll_next()] on !Unpin types.
Retrieves the next item in the stream. Read more
Retrieves the next item in the stream. Read more
Counts the number of items in the stream. Read more
Maps items of the stream to new values using a closure. Read more
Maps items to streams and then concatenates them. Read more
Concatenates inner streams. Read more
Maps items of the stream to new values using an async closure. Read more
Keeps items of the stream for which predicate returns true. Read more
Filters and maps items of the stream using a closure. Read more
Takes only the first n items of the stream. Read more
Takes items while predicate returns true. Read more
Skips the first n items of the stream. Read more
Skips items while predicate returns true. Read more
Yields every stepth item. Read more
Appends another stream to the end of this one. Read more
Clones all items. Read more
Copies all items. Read more
Collects all items in the stream into a collection. Read more
Collects all items in the fallible stream into a collection. Read more
Partitions items into those for which predicate is true and those for which it is false, and then collects them into two collections. Read more
Accumulates a computation over the stream. Read more
Accumulates a fallible computation over the stream. Read more
Maps items of the stream to new values using a state value and a closure. Read more
Fuses the stream so that it stops yielding items after the first None. Read more
Repeats the stream from beginning to end, forever. Read more
Enumerates items, mapping them to (index, item). Read more
Calls a closure on each item and passes it on. Read more
Gets the nth item of the stream. Read more
Returns the last item in the stream. Read more
Finds the first item of the stream for which predicate returns true. Read more
Applies a closure to items in the stream and returns the first Some result. Read more
Finds the index of the first item of the stream for which predicate returns true. Read more
Tests if predicate returns true for all items in the stream. Read more
Tests if predicate returns true for any item in the stream. Read more
Calls a closure on each item of the stream. Read more
Calls a fallible closure on each item of the stream, stopping on first error. Read more
Zips up two streams into a single stream of pairs. Read more
Collects a stream of pairs into a pair of collections. Read more
Merges with other stream, preferring items from self whenever both streams are ready. Read more
Merges with other stream, with no preference for either stream when both are ready. Read more
Boxes the stream and changes its type to dyn Stream + Send + 'a. Read more
Boxes the stream and changes its type to dyn Stream + 'a. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.