SendBody

Enum SendBody 

Source
pub enum SendBody<W> {
    Raw(W),
    ContentLen(ContentLenWrite<W>),
    Chunked(ChunkedWrite<W>),
}
Expand description

Represents an outgoing HTTP request stream body

Implements the Write trait to write the body to the stream

Variants§

§

Raw(W)

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

§

ContentLen(ContentLenWrite<W>)

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

§

Chunked(ChunkedWrite<W>)

The body is chunked (Transfer-Encoding: chunked)

Implementations§

Source§

impl<W> SendBody<W>
where W: Write,

Source

pub fn new(body_type: BodyType, output: W) -> SendBody<W>

Create a new body

Parameters:

  • body_type: The type of the body, as resolved using BodyType::resolve
  • output: The raw output stream
Source

pub fn is_complete(&self) -> bool

Check if the body has been completely written to

Source

pub fn needs_close(&self) -> bool

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

Source

pub async fn finish(&mut self) -> Result<(), Error<W::Error>>
where W: Write,

Finish writing the body (necessary for chunked encoding)

Source

pub fn as_raw_writer(&mut self) -> &mut W

Return a mutable reference to the underlying raw writer

Source

pub fn release(self) -> W

Release the body, returning the underlying raw writer

Trait Implementations§

Source§

impl<W> ErrorType for SendBody<W>
where W: ErrorType,

Source§

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

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

impl<W> Write for SendBody<W>
where W: Write,

Source§

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

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

async fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Source§

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

Write an entire buffer into this writer. Read more

Auto Trait Implementations§

§

impl<W> Freeze for SendBody<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for SendBody<W>
where W: RefUnwindSafe,

§

impl<W> Send for SendBody<W>
where W: Send,

§

impl<W> Sync for SendBody<W>
where W: Sync,

§

impl<W> Unpin for SendBody<W>
where W: Unpin,

§

impl<W> UnwindSafe for SendBody<W>
where W: UnwindSafe,

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.