Struct HttpResponse

Source
pub struct HttpResponse { /* private fields */ }
Expand description

An Http response

Implementations§

Source§

impl HttpResponse

Source§

impl HttpResponse

Source

pub fn parse(stream: impl Into<HttpStream>) -> Result<Self>

Source

pub fn status(&self) -> u16

Source

pub fn content_length(&self) -> usize

Source

pub fn header(&self, key: &str) -> Option<&str>

Get the value of the given header key, if present

Source

pub fn version(&self) -> f32

Source

pub fn headers(&self) -> &HashMap<String, String>

Source

pub fn body(&mut self) -> Result<Option<&[u8]>>

Reads the body from the stream into the response’s buffer.

§NOTE

This loads the whole body of the response into memory, and it’ll stick with the response for it’s lifetime. It’s not very efficient memory-wise for responses with big bodies.

For a nicer way to process a response’s body, see the read_body function.

§Errors

If some IO error happens when reading the body from the stream

§Returns

And option of &u8. A None variant means the response doesn’t have a body.

Source

pub fn has_body(&self) -> Result<bool>

Returns true if the stream has a body, and false if it’s empty.

This method is preferred to check the presence of a body, over calling body and checking the returned Option, since this function doesn’t allocate memory, nor mutates the response.

§Errors

If some IO error happens in the process of checking the stream’s availability

Source

pub fn read_body(&mut self, writer: &mut dyn Write) -> Result<()>

Reads the response’s body into writer

§Errors

If, while reading or writing, some io Error is found

Source

pub fn write_to(&mut self, out: &mut dyn Write) -> Result<usize>

Trait Implementations§

Source§

impl Debug for HttpResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for HttpResponse

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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.