Module rocket::response::content[][src]

Expand description

Contains types that set the Content-Type of a response.

Usage

Each type in this module is a Responder that wraps an existing Responder, overwriting the Content-Type of the response but otherwise delegating the response to the wrapped responder. As a convenience, (ContentType, R) where R: Responder is also a Responder that overrides the Content-Type to the value in .0:

use rocket::http::ContentType;

#[get("/")]
fn index() -> (ContentType, &'static str) {
    (ContentType::HTML, "Is this HTML? <p>Sure, why not!</p>")
}

Example

The following snippet creates a RawHtml response from a string. Normally, raw strings set their response Content-Type to text/plain. By using the RawHtml content response, the Content-Type will be set to text/html instead:

use rocket::response::content;

let response = content::RawHtml("<h1>Hello, world!</h1>");

Structs

Override the Content-Type of the response to CSS , or text/css .

Override the Content-Type of the response to HTML , or text/html .

Override the Content-Type of the response to JavaScript , or application/javascript .

Override the Content-Type of the response to JSON , or application/json .

Override the Content-Type of the response to MessagePack , or application/msgpack .

Override the Content-Type of the response to plain text , or text/plain .

Override the Content-Type of the response to XML , or text/xml .