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 status(&self) -> u16
pub fn status(&self) -> u16
Returns the status of the response that carries the body.
The status of a fetch is 200, or 206 for a request with a Range
header. A caller that sends Range reads the status to tell a part of
the object from the whole object. The status of the body of an upload
is Uploaded::status.
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 Forget for Body
impl Move for Body
impl Send for Bodywhere
Arc<Shared>: Send,
Arc<Mutex<Shared>>: Send,
Arc<Mutex<Inner>>: Send,
Bytes: Send,
RawVecInner: Send,
Arc<Inner>: Send,
Arc<[Arc<Atomic<u64>>]>: Send,
Arc<Inner>: Send,
Arc<Chan<Envelope<Request<RequestBody>, Response<Incoming>>, Semaphore>>: Send,
Arc<Gate>: Send,
Waker: Send,
Arc<Atomic<bool>>: Send,
Arc<Exchange>: Send,
impl Sync for Bodywhere
Arc<Shared>: Sync,
Arc<Mutex<Shared>>: Sync,
Arc<Mutex<Inner>>: Sync,
Bytes: Sync,
RawVecInner: Sync,
Arc<Inner>: Sync,
Arc<[Arc<Atomic<u64>>]>: Sync,
Arc<Inner>: Sync,
Arc<Chan<Envelope<Request<RequestBody>, Response<Incoming>>, Semaphore>>: Sync,
Arc<Gate>: Sync,
Waker: Sync,
Arc<Atomic<bool>>: Sync,
Arc<Exchange>: Sync,
impl Unpin for Bodywhere
Arc<Shared>: Unpin,
Arc<Mutex<Shared>>: Unpin,
Arc<Mutex<Inner>>: Unpin,
*const u8: Unpin,
Align8<*mut ()>: Unpin,
&'static Vtable: Unpin,
*const u8 is !null: Unpin,
Arc<Inner>: Unpin,
Arc<[Arc<Atomic<u64>>]>: Unpin,
Arc<Inner>: Unpin,
Arc<Chan<Envelope<Request<RequestBody>, Response<Incoming>>, Semaphore>>: Unpin,
Arc<Gate>: Unpin,
Waker: Unpin,
Arc<Atomic<bool>>: Unpin,
Arc<Exchange>: Unpin,
impl UnsafeUnpin for Bodywhere
*const ArcInner<Shared> is !null: UnsafeUnpin,
PhantomData<ArcInner<Shared>>: UnsafeUnpin,
*const ArcInner<Mutex<Shared>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Shared>>>: UnsafeUnpin,
*const ArcInner<Mutex<Inner>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Inner>>>: UnsafeUnpin,
*const u8: UnsafeUnpin,
Align8<*mut ()>: UnsafeUnpin,
&'static Vtable: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
*const ArcInner<[Arc<Atomic<u64>>]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[Arc<Atomic<u64>>]>>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
*const ArcInner<Chan<Envelope<Request<RequestBody>, Response<Incoming>>, Semaphore>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Chan<Envelope<Request<RequestBody>, Response<Incoming>>, Semaphore>>>: UnsafeUnpin,
*const ArcInner<Gate> is !null: UnsafeUnpin,
PhantomData<ArcInner<Gate>>: UnsafeUnpin,
*const (): UnsafeUnpin,
&'static RawWakerVTable: UnsafeUnpin,
*const ArcInner<Atomic<bool>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,
*const ArcInner<Exchange> is !null: UnsafeUnpin,
PhantomData<ArcInner<Exchange>>: UnsafeUnpin,
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