pub struct Body { /* private fields */ }Expand description
The response body of a fetch or of an upload.
A read gives the bytes of the response in bounded chunks. The body releases its connection and the admission permit when it reaches its end or is dropped. A body dropped before its end closes an HTTP/1.1 connection and resets an HTTP/2 stream, because the rest of the response is still in flight.
§Failures
A failure ends the body. The failed read and each later read fail with the same error. So a consumer that reads past a failure never gets a clean end of stream, and cannot take a truncated object for a complete one. The failures and their error kinds are:
- the size cap:
FileTooLarge - the progress window and the low-speed rule:
TimedOut - a transport failure:
Other.
A failure releases neither the connection nor the permit. The drop of the body releases both.
Implementations§
Source§impl Body
impl Body
Sourcepub fn validators(&self) -> &Validators
pub fn validators(&self) -> &Validators
Returns the validators to send on the next fetch of this target.
Sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Returns the Content-Length that the response declared, if it declared
one.
Sourcepub fn received(&self) -> u64
pub fn received(&self) -> u64
Returns the number of bytes that the body took from the connection.
The body takes a frame whole and gives it out in as many reads as the buffers of the caller need. So this count can be up to one frame ahead of the bytes that the caller read. The size cap applies to this count. A caller that needs the count of delivered bytes counts them in its own read loop.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Body
impl !RefUnwindSafe for Body
impl !UnwindSafe for Body
impl Send for Body
impl Sync for Body
impl Unpin for Body
impl UnsafeUnpin for Body
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> ⓘwhere
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> ⓘwhere
Self: Unpin,
Source§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self> ⓘwhere
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self> ⓘwhere
Self: Unpin,
Source§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self> ⓘwhere
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self> ⓘwhere
Self: Unpin,
Source§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self> ⓘwhere
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self> ⓘwhere
Self: Unpin,
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> ⓘwhere
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> ⓘwhere
Self: Unpin,
buf. Read moreSource§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 more