Struct pencil::wrappers::Response [] [src]

pub struct Response {
    pub status_code: u16,
    pub headers: Headers,
    pub body: Option<Box<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: Headers body: Option<Box<BodyWrite>>

Methods

impl Response
[src]

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");

fn new_empty() -> Response

Create an empty response without body.

fn status_name(&self) -> &str

Get status name.

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

Returns the response content type if available.

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.

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

Returns the response content length if available.

fn set_content_length(&mut self, value: usize)

Set content length.

Sets cookie.

Trait Implementations

impl Debug for Response
[src]

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

Formats the value using the given formatter.

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

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

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

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

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

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

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

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

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

impl From<String> for Response
[src]

fn from(s: String) -> Response

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

impl From<File> for Response
[src]

fn from(f: File) -> Response

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