pub struct Body { /* private fields */ }Expand description
An HTTP request or response body.
Most importantly, this type implements http_body::Body. This type is an
alternative to hyper::Body, with facilities to write to an existing body, and
to append bodies to one another.
Implementations§
Source§impl Body
impl Body
Sourcepub fn push_front(&mut self, chunk: impl Into<Chunk>)
pub fn push_front(&mut self, chunk: impl Into<Chunk>)
Push a new chunk onto the front of the body.
Sourcepub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Analogue to the AsyncRead traits, but without running through std::io::Result.
Attempts to read at least one byte into the buffer. Waits until at least one byte is available. If an error is encountered, returns the error; if the stream ends, returns Ok(0).
Sourcepub async fn read_into_vec(self) -> Result<Vec<u8>, Error>
pub async fn read_into_vec(self) -> Result<Vec<u8>, Error>
Read the entire body into a byte vector.
Sourcepub async fn read_into_string(self) -> Result<String, Error>
pub async fn read_into_string(self) -> Result<String, Error>
Sourcepub async fn await_ready(&mut self)
pub async fn await_ready(&mut self)
Block until the body has a chunk ready (or is known to be empty).
pub fn len(&self) -> Option<u64>
Trait Implementations§
Source§impl Body for Body
impl Body for Body
Source§fn size_hint(&self) -> SizeHint
fn size_hint(&self) -> SizeHint
This is an optional method, but implementing it correctly allows us to reduce the number of cases where bodies get sent with chunked Transfer-Encoding instead of Content-Length.
Source§fn poll_data(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Data, Self::Error>>>
fn poll_data( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Self::Data, Self::Error>>>
Source§fn poll_trailers(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Result<Option<HeaderMap>, Self::Error>>
fn poll_trailers( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<Option<HeaderMap>, Self::Error>>
HeaderMap of trailers. Read moreSource§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
true when the end of stream has been reached. Read moreSource§fn trailers(&mut self) -> Trailers<'_, Self>
fn trailers(&mut self) -> Trailers<'_, Self>
Source§fn map_data<F, B>(self, f: F) -> MapData<Self, F>
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Source§fn collect(self) -> Collect<Self>where
Self: Sized,
fn collect(self) -> Collect<Self>where
Self: Sized,
Collected body which will collect all the DATA frames
and trailers.Source§fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
Source§impl Extend<Chunk> for Body
impl Extend<Chunk> for Body
Source§fn extend<I: IntoIterator<Item = Chunk>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Chunk>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl IntoIterator for Body
impl IntoIterator for Body
Auto Trait Implementations§
impl Freeze for Body
impl !RefUnwindSafe for Body
impl Send for Body
impl Sync for Body
impl Unpin for Body
impl !UnwindSafe for Body
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more