[][src]Struct sharp_pencil::wrappers::Response

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

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: Headersbody: Option<Box<dyn BodyWrite>>

Implementations

impl Response[src]

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

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:

This example is not tested
// Content length is set automatically
let response = Response::from("Hello");

pub fn new_empty() -> Response[src]

Create an empty response without body.

pub fn status_name(&self) -> &str[src]

Get status name.

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

Returns the response content type if available.

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

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.

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

Returns the response content length if available.

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

Set content length.

Sets cookie.

Trait Implementations

impl Debug for Response[src]

impl<'a> From<&'a [u8]> for Response[src]

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

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

impl<'a> From<&'a str> for Response[src]

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

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

impl From<File> for Response[src]

fn from(f: File) -> Response[src]

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

impl From<String> for Response[src]

fn from(s: String) -> Response[src]

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

impl From<Vec<u8>> for Response[src]

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

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

Auto Trait Implementations

impl !RefUnwindSafe for Response

impl Send for Response

impl !Sync for Response

impl Unpin for Response

impl !UnwindSafe for Response

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<T> UnsafeAny for T where
    T: Any