Response

Struct Response 

Source
pub struct Response {
    pub status_code: u16,
    pub headers: Headers,
    pub body: Option<Box<dyn BodyWrite>>,
}
Expand description

Response type. It is just one container with a couple of parameters (headers, body, status code etc).

Fields§

§status_code: u16

The HTTP Status code number

§headers: Headers§body: Option<Box<dyn BodyWrite>>

Implementations§

Source§

impl Response

Source

pub fn new<T: 'static + BodyWrite>(body: T) -> Response

Create a Response. By default, the status code is 200 and content type is “text/html; charset=UTF-8”. Remember to set content length if necessary. Mostly you should just get a response that is converted from other types, which set the content length automatically. For example:

// Content length is set automatically
let response = Response::from("Hello");
Source

pub fn new_empty() -> Response

Create an empty response without body.

Source

pub fn status_name(&self) -> &str

Get status name.

Source

pub fn content_type(&self) -> Option<&ContentType>

Returns the response content type if available.

Source

pub fn set_content_type(&mut self, mimetype: &str)

Set response content type. If the mimetype passed is a mimetype starting with text/ or something that needs a charset, the charset(UTF-8) parameter is appended to it.

Source

pub fn content_length(&self) -> Option<usize>

Returns the response content length if available.

Source

pub fn set_content_length(&mut self, value: usize)

Set content length.

Sets cookie.

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<'a> From<&'a [u8]> for Response

Source§

fn from(bytes: &'a [u8]) -> Response

Convert to response body. The content length is set automatically.

Source§

impl<'a> From<&'a str> for Response

Source§

fn from(s: &'a str) -> Response

Convert to response body. The content length is set automatically.

Source§

impl From<File> for Response

Source§

fn from(f: File) -> Response

Convert to response body. The content length is set automatically if file size is available from metadata.

Source§

impl From<String> for Response

Source§

fn from(s: String) -> Response

Convert a new string to response body. The content length is set automatically.

Source§

impl From<Vec<u8>> for Response

Source§

fn from(bytes: Vec<u8>) -> Response

Convert to response body. The content length is set automatically.

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.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

impl<T> UnsafeAny for T
where T: Any,