From f8a3f70d055c94692348d5b67af07651d820b903 Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Mon, 17 Jul 2017 10:32:41 +0800 Subject: [PATCH] Seems like lifetime proliferation --- src/lib.rs | 2 +- tests/ad_hoc.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 3229ca7..c59dda8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -580,7 +580,7 @@ impl Response { /// of a route to return a value for the route. /// /// This will overwrite any existing CORS headers - pub fn respond<'r>(&self, base: response::Response<'r>) -> response::Response<'r> { + pub fn response<'r>(&self, base: response::Response<'r>) -> response::Response<'r> { let mut response = response::Response::build_from(base).finalize(); self.merge(&mut response); response diff --git a/tests/ad_hoc.rs b/tests/ad_hoc.rs index dae5f93..6c0a870 100644 --- a/tests/ad_hoc.rs +++ b/tests/ad_hoc.rs @@ -8,6 +8,7 @@ extern crate rocket_cors as cors; use std::str::FromStr; +use rocket::Response; use rocket::http::Method; use rocket::http::{Header, Status}; use rocket::local::Client; @@ -22,6 +23,29 @@ fn cors<'a>(cors: cors::Response) -> cors::Responder<'a, &'a str> { cors.responder("Hello CORS") } +// The following routes tests that the routes can be compiled with ad-hoc CORS Response/Responders + +/// Using a `Response` instead of a `Responder` +#[allow(unmounted_route)] +#[get("/")] +fn response<'a>(cors: cors::Response) -> Response<'a> { + cors.response(Response::new()) +} + +/// `Responder` with String +#[allow(unmounted_route)] +#[get("/")] +fn responder_string<'a>(cors: cors::Response) -> cors::Responder<'a, String> { + cors.responder("Hello CORS".to_string()) +} + +/// `Responder` with 'static () +#[allow(unmounted_route)] +#[get("/")] +fn responder_unit(cors: cors::Response) -> cors::Responder<'static, ()> { + cors.responder(()) +} + fn make_cors_options() -> cors::Cors { let (allowed_origins, failed_origins) = cors::AllOrSome::new_from_str_list(&["https://www.acme.com"]);