pub enum Body {
Limited(Take<Box<dyn Read + Send>>),
Chunked(ChunkedReader<Box<dyn Read + Send>>),
Unbounded(Box<dyn Read + Send>),
Empty,
Capped {
inner: Box<Body>,
remaining: u64,
},
}Expand description
An HTTP message body.
Variants§
Limited(Take<Box<dyn Read + Send>>)
Body of exactly n bytes.
Chunked(ChunkedReader<Box<dyn Read + Send>>)
Chunked transfer-encoded body.
Unbounded(Box<dyn Read + Send>)
Body read until connection close (response only).
Empty
No body (HEAD, 204, 304, …).
Capped
Any body wrapped with a hard byte cap; returns an error on overflow.
Implementations§
Source§impl Body
impl Body
Sourcepub fn read_to_vec(&mut self) -> Result<Vec<u8>>
pub fn read_to_vec(&mut self) -> Result<Vec<u8>>
Read the entire body into a Vec<u8>.
Used by the HTTP client to buffer the response body before releasing
the underlying TcpStream back to the connection pool. Buffering
first ensures the stream is fully drained and that no try_clone()
alias of the stream is live when the next request starts, which would
cause concurrent reads on the same socket and SIGSEGV on Linux/epoll.
Sourcepub fn capped(self, limit: u64) -> Self
pub fn capped(self, limit: u64) -> Self
Wrap this body with a hard byte cap. Reads beyond limit bytes return
an io::Error rather than silently truncating.
Sourcepub fn trailers(&self) -> &Header
pub fn trailers(&self) -> &Header
Return trailer headers if this is a chunked body that has been fully read. Returns an empty header for all other body types.
Sourcepub fn into_trailers(self) -> Header
pub fn into_trailers(self) -> Header
Consume the body and return any trailer headers (chunked bodies only).
Trait Implementations§
Source§impl Read for Body
impl Read for Body
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)