diff --git a/examples/redirect/src/main.rs b/examples/redirect/src/main.rs index 066957ec..d692c83a 100644 --- a/examples/redirect/src/main.rs +++ b/examples/redirect/src/main.rs @@ -9,7 +9,7 @@ use rocket::response::Redirect; #[get("/")] fn root() -> Redirect { - Redirect::to("/login") + Redirect::to(uri!(login)) } #[get("/login")] diff --git a/lib/src/http/uri/uri_display.rs b/lib/src/http/uri/uri_display.rs index 43562086..a4f49ddd 100644 --- a/lib/src/http/uri/uri_display.rs +++ b/lib/src/http/uri/uri_display.rs @@ -144,7 +144,7 @@ use self::priv_encode_set::PATH_ENCODE_SET; /// /// #[get("/name/")] /// fn redirector(name: Name) -> Redirect { -/// Redirect::to(uri!(real: name).as_str()) +/// Redirect::to(uri!(real: name)) /// } /// /// #[get("/")] diff --git a/lib/src/response/redirect.rs b/lib/src/response/redirect.rs index 9d9b1b4d..ef891780 100644 --- a/lib/src/response/redirect.rs +++ b/lib/src/response/redirect.rs @@ -1,13 +1,13 @@ use request::Request; use response::{Response, Responder}; -use http::hyper::header; +use http::uri::Uri; use http::Status; /// An empty redirect response to a given URL. /// /// This type simplifies returning a redirect response to the client. #[derive(Debug)] -pub struct Redirect(Status, String); +pub struct Redirect(Status, Uri<'static>); impl Redirect { /// Construct a temporary "see other" (303) redirect response. This is the @@ -23,8 +23,8 @@ impl Redirect { /// # #[allow(unused_variables)] /// let redirect = Redirect::to("/other_url"); /// ``` - pub fn to(uri: &str) -> Redirect { - Redirect(Status::SeeOther, String::from(uri)) + pub fn to>>(uri: U) -> Redirect { + Redirect(Status::SeeOther, uri.into()) } /// Construct a "temporary" (307) redirect response. This response instructs @@ -41,8 +41,8 @@ impl Redirect { /// # #[allow(unused_variables)] /// let redirect = Redirect::temporary("/other_url"); /// ``` - pub fn temporary(uri: &str) -> Redirect { - Redirect(Status::TemporaryRedirect, String::from(uri)) + pub fn temporary>>(uri: U) -> Redirect { + Redirect(Status::TemporaryRedirect, uri.into()) } /// Construct a "permanent" (308) redirect response. This redirect must only @@ -60,8 +60,8 @@ impl Redirect { /// # #[allow(unused_variables)] /// let redirect = Redirect::permanent("/other_url"); /// ``` - pub fn permanent(uri: &str) -> Redirect { - Redirect(Status::PermanentRedirect, String::from(uri)) + pub fn permanent>>(uri: U) -> Redirect { + Redirect(Status::PermanentRedirect, uri.into()) } /// Construct a temporary "found" (302) redirect response. This response @@ -79,8 +79,8 @@ impl Redirect { /// # #[allow(unused_variables)] /// let redirect = Redirect::found("/other_url"); /// ``` - pub fn found(uri: &str) -> Redirect { - Redirect(Status::Found, String::from(uri)) + pub fn found>>(uri: U) -> Redirect { + Redirect(Status::Found, uri.into()) } /// Construct a permanent "moved" (301) redirect response. This response @@ -96,8 +96,8 @@ impl Redirect { /// # #[allow(unused_variables)] /// let redirect = Redirect::moved("/other_url"); /// ``` - pub fn moved(uri: &str) -> Redirect { - Redirect(Status::MovedPermanently, String::from(uri)) + pub fn moved>>(uri: U) -> Redirect { + Redirect(Status::MovedPermanently, uri.into()) } } @@ -108,7 +108,7 @@ impl Responder<'static> for Redirect { fn respond_to(self, _: &Request) -> Result, Status> { Response::build() .status(self.0) - .header(header::Location(self.1)) + .raw_header("Location", self.1.to_string()) .ok() } }