Struct trillium_http::ReceivedBody [−][src]
pub struct ReceivedBody<'conn, Transport> { /* fields omitted */ }
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
impl<'conn, Transport> ReceivedBody<'conn, Transport> where
Transport: AsyncRead + Unpin + Send + Sync + 'static,
impl<'conn, Transport> ReceivedBody<'conn, Transport> where
Transport: AsyncRead + Unpin + Send + Sync + 'static,
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.
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
.
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.
takes the static transport from this received body
Trait Implementations
impl<'conn, Transport> AsyncRead for ReceivedBody<'conn, Transport> where
Transport: AsyncRead + Unpin + Send + Sync + 'static,
impl<'conn, Transport> AsyncRead for ReceivedBody<'conn, Transport> where
Transport: AsyncRead + Unpin + Send + Sync + 'static,
Attempt to read from the AsyncRead
into buf
. Read more
Performs the conversion.
impl<'conn, Transport> Stream for ReceivedBody<'conn, Transport> where
Transport: AsyncRead + Unpin + Send + Sync + 'static,
impl<'conn, Transport> Stream for ReceivedBody<'conn, Transport> where
Transport: AsyncRead + Unpin + Send + Sync + 'static,
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
Auto Trait Implementations
impl<'conn, Transport> !RefUnwindSafe for ReceivedBody<'conn, Transport>
impl<'conn, Transport> Send for ReceivedBody<'conn, Transport> where
Transport: Send,
impl<'conn, Transport> Sync for ReceivedBody<'conn, Transport> where
Transport: Sync,
impl<'conn, Transport> Unpin for ReceivedBody<'conn, Transport> where
Transport: Unpin,
impl<'conn, Transport> !UnwindSafe for ReceivedBody<'conn, Transport>
Blanket Implementations
Reads some bytes from the byte stream. Read more
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
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
Creates an adapter which will chain this stream with another. Read more
Mutably borrows from an owned value. Read more
A convenience for calling [Stream::poll_next()
] on !
Unpin
types.
Retrieves the next item in the stream. Read more
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> where
Self: Stream<Item = Result<T, E>> + Unpin,
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> where
Self: Stream<Item = Result<T, E>> + Unpin,
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
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Takes items while predicate
returns true
. Read more
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Skips items while predicate
returns true
. 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
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
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
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> where
F: FnMut(T, Self::Item) -> T,
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> where
F: FnMut(T, Self::Item) -> T,
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
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 n
th 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
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
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
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
pub fn vzip(self) -> V