Body

Enum Body 

Source
pub enum Body<'b, R> {
    Raw(PartiallyRead<'b, R>),
    ContentLen(ContentLenRead<PartiallyRead<'b, R>>),
    Chunked(ChunkedRead<'b, PartiallyRead<'b, R>>),
}
Expand description

Represents an incoming HTTP request stream body

Implements the Read trait to read the body from the stream

Variants§

§

Raw(PartiallyRead<'b, R>)

The body is raw and should be read as is (only possible for HTTP responses with connection = Close)

§

ContentLen(ContentLenRead<PartiallyRead<'b, R>>)

The body is of a known length (Content-Length)

§

Chunked(ChunkedRead<'b, PartiallyRead<'b, R>>)

The body is chunked (Transfer-Encoding: chunked)

Implementations§

Source§

impl<'b, R> Body<'b, R>
where R: Read,

Source

pub fn new( body_type: BodyType, buf: &'b mut [u8], read_len: usize, input: R, ) -> Self

Create a new body

Parameters:

  • body_type: The type of the body, as resolved using BodyType::resolve
  • buf: The buffer to use for reading the body
  • read_len: The length of the buffer that has already been read when processing the icoming headers
  • input: The raw input stream
Source

pub fn needs_close(&self) -> bool

Check if the body needs to be closed (i.e. the underlying input stream cannot be re-used for Keep-Alive connections)

Source

pub fn is_complete(&self) -> bool

Check if the body has been completely read

Source

pub fn as_raw_reader(&mut self) -> &mut R

Return a mutable reference to the underlying raw reader

Source

pub fn release(self) -> R

Release the body, returning the underlying raw reader

Trait Implementations§

Source§

impl<R> ErrorType for Body<'_, R>
where R: ErrorType,

Source§

type Error = Error<<R as ErrorType>::Error>

Error type of all the IO operations on this type.
Source§

impl<R> Read for Body<'_, R>
where R: Read,

Source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more

Auto Trait Implementations§

§

impl<'b, R> Freeze for Body<'b, R>
where R: Freeze,

§

impl<'b, R> RefUnwindSafe for Body<'b, R>
where R: RefUnwindSafe,

§

impl<'b, R> Send for Body<'b, R>
where R: Send,

§

impl<'b, R> Sync for Body<'b, R>
where R: Sync,

§

impl<'b, R> Unpin for Body<'b, R>
where R: Unpin,

§

impl<'b, R> !UnwindSafe for Body<'b, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.