Change to catch up with latest rocket master
- rocket::handler -> rocket::route - request.get_param() -> request.param - Change attach -> ignite and ignite -> build - Update lifetime signature of FromRequest
This commit is contained in:
parent
305971023d
commit
869441dbf8
|
@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
.to_cors()?;
|
.to_cors()?;
|
||||||
|
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![cors])
|
.mount("/", routes![cors])
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
.launch()
|
.launch()
|
||||||
|
|
|
@ -47,7 +47,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
.to_cors()?;
|
.to_cors()?;
|
||||||
|
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![responder, response])
|
.mount("/", routes![responder, response])
|
||||||
// Mount the routes to catch all the OPTIONS pre-flight requests
|
// Mount the routes to catch all the OPTIONS pre-flight requests
|
||||||
.mount("/", rocket_cors::catch_all_options_routes())
|
.mount("/", rocket_cors::catch_all_options_routes())
|
||||||
|
|
|
@ -71,7 +71,7 @@ fn cors_options() -> CorsOptions {
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() -> Result<(), Error> {
|
async fn main() -> Result<(), Error> {
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![borrowed, response, owned, owned_options,])
|
.mount("/", routes![borrowed, response, owned, owned_options,])
|
||||||
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
|
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
|
||||||
.manage(cors_options().to_cors().expect("To not fail"))
|
.manage(cors_options().to_cors().expect("To not fail"))
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn cors_options_all() -> CorsOptions {
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() -> Result<(), Error> {
|
async fn main() -> Result<(), Error> {
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![app, ping, ping_options,])
|
.mount("/", routes![app, ping, ping_options,])
|
||||||
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
|
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
|
||||||
.manage(cors_options().to_cors().expect("To not fail"))
|
.manage(cors_options().to_cors().expect("To not fail"))
|
||||||
|
|
|
@ -19,14 +19,14 @@ enum CorsValidation {
|
||||||
struct FairingErrorRoute {}
|
struct FairingErrorRoute {}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl rocket::handler::Handler for FairingErrorRoute {
|
impl rocket::route::Handler for FairingErrorRoute {
|
||||||
async fn handle<'r, 's: 'r>(
|
async fn handle<'r>(
|
||||||
&'s self,
|
&self,
|
||||||
request: &'r Request<'_>,
|
request: &'r Request<'_>,
|
||||||
_: rocket::Data,
|
_: rocket::Data,
|
||||||
) -> rocket::handler::Outcome<'r> {
|
) -> rocket::route::Outcome<'r> {
|
||||||
let status = request
|
let status = request
|
||||||
.get_param::<u16>(0)
|
.param::<u16>(0)
|
||||||
.unwrap_or(Ok(0))
|
.unwrap_or(Ok(0))
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
error_!("Fairing Error Handling Route error: {:?}", e);
|
error_!("Fairing Error Handling Route error: {:?}", e);
|
||||||
|
@ -102,13 +102,13 @@ impl rocket::fairing::Fairing for Cors {
|
||||||
fn info(&self) -> rocket::fairing::Info {
|
fn info(&self) -> rocket::fairing::Info {
|
||||||
rocket::fairing::Info {
|
rocket::fairing::Info {
|
||||||
name: "CORS",
|
name: "CORS",
|
||||||
kind: rocket::fairing::Kind::Attach
|
kind: rocket::fairing::Kind::Ignite
|
||||||
| rocket::fairing::Kind::Request
|
| rocket::fairing::Kind::Request
|
||||||
| rocket::fairing::Kind::Response,
|
| rocket::fairing::Kind::Response,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_attach(&self, rocket: rocket::Rocket) -> Result<rocket::Rocket, rocket::Rocket> {
|
async fn on_ignite(&self, rocket: rocket::Rocket<rocket::Build>) -> rocket::fairing::Result {
|
||||||
Ok(rocket.mount(
|
Ok(rocket.mount(
|
||||||
&self.fairing_route_base,
|
&self.fairing_route_base,
|
||||||
vec![fairing_route(self.fairing_route_rank)],
|
vec![fairing_route(self.fairing_route_rank)],
|
||||||
|
@ -164,8 +164,8 @@ mod tests {
|
||||||
.expect("Not to fail")
|
.expect("Not to fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rocket(fairing: Cors) -> Rocket {
|
fn rocket(fairing: Cors) -> Rocket<rocket::Build> {
|
||||||
Rocket::ignite().attach(fairing)
|
Rocket::build().attach(fairing)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -187,8 +187,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_test]
|
#[rocket::async_test]
|
||||||
async fn error_route_is_mounted_on_attach() {
|
async fn error_route_is_mounted_on_ignite() {
|
||||||
let rocket = rocket(make_cors_options());
|
let rocket = rocket(make_cors_options()).ignite().await.expect("to ignite");
|
||||||
|
|
||||||
let expected_uri = format!("{}/<status>", CORS_ROOT);
|
let expected_uri = format!("{}/<status>", CORS_ROOT);
|
||||||
let error_route = rocket
|
let error_route = rocket
|
||||||
|
|
|
@ -134,11 +134,11 @@ impl fmt::Display for Origin {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for Origin {
|
impl<'r> FromRequest<'r> for Origin {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
async fn from_request(
|
async fn from_request(
|
||||||
request: &'a rocket::Request<'r>,
|
request: &'r rocket::Request<'_>,
|
||||||
) -> request::Outcome<Self, crate::Error> {
|
) -> request::Outcome<Self, crate::Error> {
|
||||||
Origin::from_request_sync(request)
|
Origin::from_request_sync(request)
|
||||||
}
|
}
|
||||||
|
@ -180,11 +180,11 @@ impl FromStr for AccessControlRequestMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestMethod {
|
impl<'r> FromRequest<'r> for AccessControlRequestMethod {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
async fn from_request(
|
async fn from_request(
|
||||||
request: &'a rocket::Request<'r>,
|
request: &'r rocket::Request<'_>,
|
||||||
) -> request::Outcome<Self, crate::Error> {
|
) -> request::Outcome<Self, crate::Error> {
|
||||||
AccessControlRequestMethod::from_request_sync(request)
|
AccessControlRequestMethod::from_request_sync(request)
|
||||||
}
|
}
|
||||||
|
@ -238,11 +238,11 @@ impl FromStr for AccessControlRequestHeaders {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestHeaders {
|
impl<'r> FromRequest<'r> for AccessControlRequestHeaders {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
async fn from_request(
|
async fn from_request(
|
||||||
request: &'a rocket::Request<'r>,
|
request: &'r rocket::Request<'_>,
|
||||||
) -> request::Outcome<Self, crate::Error> {
|
) -> request::Outcome<Self, crate::Error> {
|
||||||
AccessControlRequestHeaders::from_request_sync(request)
|
AccessControlRequestHeaders::from_request_sync(request)
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ mod tests {
|
||||||
|
|
||||||
/// Make a client with no routes for unit testing
|
/// Make a client with no routes for unit testing
|
||||||
fn make_client() -> Client {
|
fn make_client() -> Client {
|
||||||
let rocket = rocket::ignite();
|
let rocket = rocket::build();
|
||||||
Client::tracked(rocket).expect("valid rocket instance")
|
Client::tracked(rocket).expect("valid rocket instance")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -1516,10 +1516,10 @@ impl<'r, 'o: 'r> Guard<'r> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> {
|
impl<'r> FromRequest<'r> for Guard<'r> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> rocket::request::Outcome<Self, Self::Error> {
|
async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome<Self, Self::Error> {
|
||||||
let options = match request.guard::<State<'_, Cors>>().await {
|
let options = match request.guard::<State<'_, Cors>>().await {
|
||||||
Outcome::Success(options) => options,
|
Outcome::Success(options) => options,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -2009,15 +2009,15 @@ pub fn catch_all_options_routes() -> Vec<rocket::Route> {
|
||||||
struct CatchAllOptionsRouteHandler {}
|
struct CatchAllOptionsRouteHandler {}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl rocket::handler::Handler for CatchAllOptionsRouteHandler {
|
impl rocket::route::Handler for CatchAllOptionsRouteHandler {
|
||||||
async fn handle<'r, 's: 'r>(
|
async fn handle<'r>(
|
||||||
&'s self,
|
&self,
|
||||||
request: &'r Request<'_>,
|
request: &'r Request<'_>,
|
||||||
_: rocket::Data,
|
_: rocket::Data,
|
||||||
) -> rocket::handler::Outcome<'r> {
|
) -> rocket::route::Outcome<'r> {
|
||||||
let guard: Guard<'_> = match request.guard().await {
|
let guard: Guard<'_> = match request.guard().await {
|
||||||
Outcome::Success(guard) => guard,
|
Outcome::Success(guard) => guard,
|
||||||
Outcome::Failure((status, _)) => return rocket::handler::Outcome::failure(status),
|
Outcome::Failure((status, _)) => return rocket::route::Outcome::failure(status),
|
||||||
Outcome::Forward(()) => unreachable!("Should not be reachable"),
|
Outcome::Forward(()) => unreachable!("Should not be reachable"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2026,7 +2026,7 @@ impl rocket::handler::Handler for CatchAllOptionsRouteHandler {
|
||||||
request
|
request
|
||||||
);
|
);
|
||||||
|
|
||||||
rocket::handler::Outcome::from(request, guard.responder(()))
|
rocket::route::Outcome::from(request, guard.responder(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2080,7 +2080,7 @@ mod tests {
|
||||||
|
|
||||||
/// Make a client with no routes for unit testing
|
/// Make a client with no routes for unit testing
|
||||||
fn make_client() -> Client {
|
fn make_client() -> Client {
|
||||||
let rocket = rocket::ignite();
|
let rocket = rocket::build();
|
||||||
Client::tracked(rocket).expect("valid rocket instance")
|
Client::tracked(rocket).expect("valid rocket instance")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ fn make_cors() -> Cors {
|
||||||
.expect("To not fail")
|
.expect("To not fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket<rocket::Build> {
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![cors, panicking_route])
|
.mount("/", routes![cors, panicking_route])
|
||||||
.attach(make_cors())
|
.attach(make_cors())
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,8 @@ fn make_cors() -> cors::Cors {
|
||||||
.expect("To not fail")
|
.expect("To not fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_rocket() -> rocket::Rocket {
|
fn make_rocket() -> rocket::Rocket<rocket::Build> {
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![cors_responder, panicking_route])
|
.mount("/", routes![cors_responder, panicking_route])
|
||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn request_headers(
|
||||||
/// Tests that all the request headers are parsed correcly in a HTTP request
|
/// Tests that all the request headers are parsed correcly in a HTTP request
|
||||||
#[test]
|
#[test]
|
||||||
fn request_headers_round_trip_smoke_test() {
|
fn request_headers_round_trip_smoke_test() {
|
||||||
let rocket = rocket::ignite().mount("/", routes![request_headers]);
|
let rocket = rocket::build().mount("/", routes![request_headers]);
|
||||||
let client = Client::tracked(rocket).expect("A valid Rocket client");
|
let client = Client::tracked(rocket).expect("A valid Rocket client");
|
||||||
|
|
||||||
let origin_header = Header::new(ORIGIN.as_str(), "https://foo.bar.xyz");
|
let origin_header = Header::new(ORIGIN.as_str(), "https://foo.bar.xyz");
|
||||||
|
|
|
@ -95,8 +95,8 @@ fn make_different_cors_options() -> CorsOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket<rocket::Build> {
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![cors, panicking_route])
|
.mount("/", routes![cors, panicking_route])
|
||||||
.mount("/", routes![owned, owned_options])
|
.mount("/", routes![owned, owned_options])
|
||||||
.mount("/", catch_all_options_routes()) // mount the catch all routes
|
.mount("/", catch_all_options_routes()) // mount the catch all routes
|
||||||
|
|
|
@ -61,8 +61,8 @@ fn cors_options_all() -> CorsOptions {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket<rocket::Build> {
|
||||||
rocket::ignite()
|
rocket::build()
|
||||||
.mount("/", routes![app, ping, ping_options,])
|
.mount("/", routes![app, ping, ping_options,])
|
||||||
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
|
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
|
||||||
.manage(cors_options().to_cors().expect("Not to fail"))
|
.manage(cors_options().to_cors().expect("Not to fail"))
|
||||||
|
|
Loading…
Reference in New Issue