Struct rouille::Response [] [src]

pub struct Response {
    pub status_code: u16,
    pub headers: Vec<(String, String)>,
    pub data: ResponseBody,
}

Contains a prototype of a response. The response is only sent when you call Request::respond.

Fields

status_code

The status code to return to the user.

headers

List of headers to be returned in the response.

Note that important headers such as Connection or Content-Length will be ignored from this list.

data

An opaque type that contains the body of the response.

Methods

impl Response

fn from_error(err: &RouteError) -> Response

UNSTABLE. Builds a default response to handle the given route error.

Important: don't use this in a real website. This function is just a convenience when prototyping.

For authentication-related errors, you are strongly encouraged to handle them yourself.

fn redirect(target: &str) -> Response

Builds a Response that redirects the user to another URL.

fn html<D>(content: D) -> Response where D: Into<Vec<u8>>

Builds a Response that outputs HTML.

fn text<S>(text: S) -> Response where S: Into<String>

Builds a Response that outputs plain text.

fn json<T>(content: &T) -> Response where T: Encodable

Builds a Response that outputs JSON.

fn basic_http_auth_login_required(realm: &str) -> Response

Builds a Response that returns a 401 Not Authorized status and a WWW-Authenticate header.

fn with_status_code(self, code: u16) -> Response

Changes the status code of the response.