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 to the client when you return the Response object from your request handler. This means that you are free to create as many Response objects as you want.

Fields

The status code to return to the user.

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.

An opaque type that contains the body of the response.

Methods

impl Response
[src]

Returns true if the status code of this Response indicates success.

This is the range [200-399].

Example

use rouille::Response;
let response = Response::text("hello world");
assert!(response.success());

Shortcut for !response.success().

Example

use rouille::Response;
let response = Response::empty_400();
assert!(response.error());

Builds a Response that redirects the user to another URL with a 303 status code.

Example

use rouille::Response;
let response = Response::redirect("/foo");

Builds a Response that outputs HTML.

Example

use rouille::Response;
let response = Response::text("<p>hello <strong>world</strong></p>");

Builds a Response that outputs SVG.

Example

use rouille::Response;
let response = Response::svg("<svg xmlns='http://www.w3.org/2000/svg'/>");

Builds a Response that outputs plain text.

Example

use rouille::Response;
let response = Response::text("hello world");

Builds a Response that outputs JSON.

Example

extern crate rustc_serialize;
use rouille::Response;

#[derive(RustcEncodable)]
struct MyStruct {
    field1: String,
    field2: i32,
}

let response = Response::json(&MyStruct { field1: "hello".to_owned(), field2: 5 });
// The Response will contain something like `{ field1: "hello", field2: 5 }`

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

Example

use rouille::Response;
let response = Response::basic_http_auth_login_required("realm");

Builds an empty Response with a 400 status code.

Example

use rouille::Response;
let response = Response::empty_400();

Builds an empty Response with a 404 status code.

Example

use rouille::Response;
let response = Response::empty_404();

Changes the status code of the response.

Example

use rouille::Response;
let response = Response::text("hello world").with_status_code(500);