Struct Response

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

Wrapper over an HTTP Response.

The Response is created using a Version and a StatusCode. When creating a Response object, the body is initialized to None and the header is initialized with the default value. The body can be updated with a call to set_body. The header can be updated with set_content_type and set_server.

Implementations§

Source§

impl Response

Source

pub fn new(http_version: Version, status_code: StatusCode) -> Self

Creates a new HTTP Response with an empty body.

Source

pub fn set_body(&mut self, body: Body)

Updates the body of the Response.

This function has side effects because it also updates the headers:

  • ContentLength: this is set to the length of the specified body.
Source

pub fn set_content_type(&mut self, content_type: MediaType)

Updates the content type of the Response.

Source

pub fn set_deprecation(&mut self)

Marks the Response as deprecated.

Source

pub fn set_encoding(&mut self)

Updates the encoding type of Response.

Source

pub fn set_server(&mut self, server: &str)

Sets the HTTP response server.

Source

pub fn set_allow(&mut self, methods: Vec<Method>)

Sets the HTTP allowed methods.

Source

pub fn allow_method(&mut self, method: Method)

Allows a specific HTTP method.

Source

pub fn write_all<T: Write>(&self, buf: &mut T) -> Result<(), WriteError>

Writes the content of the Response to the specified buf.

§Errors

Returns an error when the buffer is not large enough.

Source

pub fn status(&self) -> StatusCode

Returns the Status Code of the Response.

Source

pub fn body(&self) -> Option<Body>

Returns the Body of the response. If the response does not have a body, it returns None.

Source

pub fn content_length(&self) -> i32

Returns the Content Length of the response.

Source

pub fn content_type(&self) -> MediaType

Returns the Content Type of the response.

Source

pub fn deprecation(&self) -> bool

Returns the deprecation status of the response.

Source

pub fn http_version(&self) -> Version

Returns the HTTP Version of the response.

Source

pub fn allow(&self) -> Vec<Method>

Returns the allowed HTTP methods.

Trait Implementations§

Source§

impl Debug for Response

Source§

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

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

impl PartialEq for Response

Source§

fn eq(&self, other: &Response) -> 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.
Source§

impl Eq for Response

Source§

impl StructuralPartialEq for Response

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.