diff --git a/contrib/lib/src/templates/mod.rs b/contrib/lib/src/templates/mod.rs index 0409b8fc..ac06ba0f 100644 --- a/contrib/lib/src/templates/mod.rs +++ b/contrib/lib/src/templates/mod.rs @@ -140,7 +140,7 @@ use std::error::Error; use rocket::{Rocket, Orbit, Ignite, Sentinel}; use rocket::request::Request; use rocket::fairing::Fairing; -use rocket::response::{self, Content, Responder}; +use rocket::response::{self, Responder}; use rocket::http::{ContentType, Status}; const DEFAULT_TEMPLATE_DIR: &str = "templates"; @@ -430,7 +430,7 @@ impl<'r> Responder<'r, 'static> for Template { self.finalize(&ctxt)? }; - Content(content_type, render).respond_to(req) + (content_type, render).respond_to(req) } } diff --git a/core/lib/src/response/content.rs b/core/lib/src/response/content.rs index 94eed797..42ff34a0 100644 --- a/core/lib/src/response/content.rs +++ b/core/lib/src/response/content.rs @@ -7,6 +7,21 @@ //! remainder of the response to the wrapped responder. This allows for setting //! the Content-Type of a type that doesn't set it itself or for overriding one //! that does. +//! +//! The [`Custom`] type allows responding with _any_ `Content-Type`. As a +//! convenience, `(ContentType, R)` where `R: Responder` is _also_ a +//! `Responder`, identical to `Custom`. +//! +//! ```rust +//! # use rocket::get; +//! use rocket::http::ContentType; +//! +//! #[get("/")] +//! fn index() -> (ContentType, &'static str) { +//! (ContentType::HTML, "Is this HTML?
Sure, why not!
") +//! } +//! ``` + //! //! # Example //! @@ -35,18 +50,18 @@ use crate::http::ContentType; /// Set the Content-Type of a string to PDF. /// /// ```rust -/// use rocket::response::content::Content; +/// use rocket::response::content::Custom; /// use rocket::http::ContentType; /// /// # #[allow(unused_variables)] -/// let response = Content(ContentType::PDF, "Hi."); +/// let response = Custom(ContentType::PDF, "Hi."); /// ``` #[derive(Debug, Clone, PartialEq)] -pub struct Content