Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest master Rocket version #89

Merged
merged 7 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ serialization = ["serde", "serde_derive", "unicase_serde"]

[dependencies]
regex = "1.1"
rocket = { branch = "master", git = "https://github.com/SergioBenitez/Rocket.git", default-features = false }
rocket = { rev="801e04bd5369eb39e126c75f6d11e1e9597304d8", git = "https://github.com/SergioBenitez/Rocket.git", default-features = false }
log = "0.4"
unicase = "2.0"
url = "2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
.to_cors()?;

rocket::ignite()
rocket::build()
.mount("/", routes![cors])
.attach(cors)
.launch()
Expand Down
2 changes: 1 addition & 1 deletion examples/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
.to_cors()?;

rocket::ignite()
rocket::build()
.mount("/", routes![responder, response])
// Mount the routes to catch all the OPTIONS pre-flight requests
.mount("/", rocket_cors::catch_all_options_routes())
Expand Down
2 changes: 1 addition & 1 deletion examples/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn cors_options() -> CorsOptions {

#[rocket::main]
async fn main() -> Result<(), Error> {
rocket::ignite()
rocket::build()
.mount("/", routes![borrowed, response, owned, owned_options,])
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
.manage(cors_options().to_cors().expect("To not fail"))
Expand Down
2 changes: 1 addition & 1 deletion examples/mix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn cors_options_all() -> CorsOptions {

#[rocket::main]
async fn main() -> Result<(), Error> {
rocket::ignite()
rocket::build()
.mount("/", routes![app, ping, ping_options,])
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
.manage(cors_options().to_cors().expect("To not fail"))
Expand Down
28 changes: 16 additions & 12 deletions src/fairing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Fairing implementation

#[allow(unused_imports)]
use ::log::{error, info};
use rocket::http::{self, uri::Origin, Status};
use rocket::{self, error_, info_, log_, outcome::Outcome, Request};
use rocket::{self, error_, info_, outcome::Outcome, Request};

use crate::{
actual_request_response, origin, preflight_response, request_headers, validate, Cors, Error,
Expand All @@ -19,14 +20,14 @@ enum CorsValidation {
struct FairingErrorRoute {}

#[rocket::async_trait]
impl rocket::handler::Handler for FairingErrorRoute {
async fn handle<'r, 's: 'r>(
&'s self,
impl rocket::route::Handler for FairingErrorRoute {
async fn handle<'r>(
&self,
request: &'r Request<'_>,
_: rocket::Data,
) -> rocket::handler::Outcome<'r> {
) -> rocket::route::Outcome<'r> {
let status = request
.get_param::<u16>(0)
.param::<u16>(0)
.unwrap_or(Ok(0))
.unwrap_or_else(|e| {
error_!("Fairing Error Handling Route error: {:?}", e);
Expand Down Expand Up @@ -102,13 +103,13 @@ impl rocket::fairing::Fairing for Cors {
fn info(&self) -> rocket::fairing::Info {
rocket::fairing::Info {
name: "CORS",
kind: rocket::fairing::Kind::Attach
kind: rocket::fairing::Kind::Ignite
| rocket::fairing::Kind::Request
| 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(
&self.fairing_route_base,
vec![fairing_route(self.fairing_route_rank)],
Expand Down Expand Up @@ -164,8 +165,8 @@ mod tests {
.expect("Not to fail")
}

fn rocket(fairing: Cors) -> Rocket {
Rocket::ignite().attach(fairing)
fn rocket(fairing: Cors) -> Rocket<rocket::Build> {
Rocket::build().attach(fairing)
}

#[test]
Expand All @@ -187,8 +188,11 @@ mod tests {
}

#[rocket::async_test]
async fn error_route_is_mounted_on_attach() {
let rocket = rocket(make_cors_options());
async fn error_route_is_mounted_on_ignite() {
let rocket = rocket(make_cors_options())
.ignite()
.await
.expect("to ignite");

let expected_uri = format!("{}/<status>", CORS_ROOT);
let error_route = rocket
Expand Down
14 changes: 7 additions & 7 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ impl fmt::Display for Origin {
}

#[rocket::async_trait]
impl<'a, 'r> FromRequest<'a, 'r> for Origin {
impl<'r> FromRequest<'r> for Origin {
type Error = crate::Error;

async fn from_request(
request: &'a rocket::Request<'r>,
request: &'r rocket::Request<'_>,
) -> request::Outcome<Self, crate::Error> {
Origin::from_request_sync(request)
}
Expand Down Expand Up @@ -180,11 +180,11 @@ impl FromStr for AccessControlRequestMethod {
}

#[rocket::async_trait]
impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestMethod {
impl<'r> FromRequest<'r> for AccessControlRequestMethod {
type Error = crate::Error;

async fn from_request(
request: &'a rocket::Request<'r>,
request: &'r rocket::Request<'_>,
) -> request::Outcome<Self, crate::Error> {
AccessControlRequestMethod::from_request_sync(request)
}
Expand Down Expand Up @@ -238,11 +238,11 @@ impl FromStr for AccessControlRequestHeaders {
}

#[rocket::async_trait]
impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestHeaders {
impl<'r> FromRequest<'r> for AccessControlRequestHeaders {
type Error = crate::Error;

async fn from_request(
request: &'a rocket::Request<'r>,
request: &'r rocket::Request<'_>,
) -> request::Outcome<Self, crate::Error> {
AccessControlRequestHeaders::from_request_sync(request)
}
Expand All @@ -266,7 +266,7 @@ mod tests {

/// Make a client with no routes for unit testing
fn make_client() -> Client {
let rocket = rocket::ignite();
let rocket = rocket::build();
Client::tracked(rocket).expect("valid rocket instance")
}

Expand Down
41 changes: 17 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,13 @@ use std::marker::PhantomData;
use std::ops::Deref;
use std::str::FromStr;

#[allow(unused_imports)]
use ::log::{debug, error, info};
use regex::RegexSet;
use rocket::http::{self, Status};
use rocket::request::{FromRequest, Request};
use rocket::response;
use rocket::{debug_, error_, info_, log_, outcome::Outcome, State};
use rocket::{debug_, error_, info_, outcome::Outcome, State};
#[cfg(feature = "serialization")]
use serde_derive::{Deserialize, Serialize};

Expand Down Expand Up @@ -1516,10 +1517,10 @@ impl<'r, 'o: 'r> Guard<'r> {
}

#[rocket::async_trait]
impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> {
impl<'r> FromRequest<'r> for Guard<'r> {
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 {
Outcome::Success(options) => options,
_ => {
Expand Down Expand Up @@ -1988,36 +1989,28 @@ fn actual_request_response(options: &Cors, origin: &str) -> Response {
///
/// See the documentation at the [crate root](index.html) for usage information.
pub fn catch_all_options_routes() -> Vec<rocket::Route> {
vec![
rocket::Route::ranked(
isize::max_value(),
http::Method::Options,
"/",
CatchAllOptionsRouteHandler {},
),
rocket::Route::ranked(
isize::max_value(),
http::Method::Options,
"/<catch_all_options_route..>",
CatchAllOptionsRouteHandler {},
),
]
vec![rocket::Route::ranked(
isize::MAX,
http::Method::Options,
"/<catch_all_options_route..>",
CatchAllOptionsRouteHandler {},
)]
}

/// Handler for the "catch all options route"
#[derive(Clone)]
struct CatchAllOptionsRouteHandler {}

#[rocket::async_trait]
impl rocket::handler::Handler for CatchAllOptionsRouteHandler {
async fn handle<'r, 's: 'r>(
&'s self,
impl rocket::route::Handler for CatchAllOptionsRouteHandler {
async fn handle<'r>(
&self,
request: &'r Request<'_>,
_: rocket::Data,
) -> rocket::handler::Outcome<'r> {
) -> rocket::route::Outcome<'r> {
let guard: Guard<'_> = match request.guard().await {
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"),
};

Expand All @@ -2026,7 +2019,7 @@ impl rocket::handler::Handler for CatchAllOptionsRouteHandler {
request
);

rocket::handler::Outcome::from(request, guard.responder(()))
rocket::route::Outcome::from(request, guard.responder(()))
}
}

Expand Down Expand Up @@ -2080,7 +2073,7 @@ mod tests {

/// Make a client with no routes for unit testing
fn make_client() -> Client {
let rocket = rocket::ignite();
let rocket = rocket::build();
Client::tracked(rocket).expect("valid rocket instance")
}

Expand Down
4 changes: 2 additions & 2 deletions tests/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn make_cors() -> Cors {
.expect("To not fail")
}

fn rocket() -> rocket::Rocket {
rocket::ignite()
fn rocket() -> rocket::Rocket<rocket::Build> {
rocket::build()
.mount("/", routes![cors, panicking_route])
.attach(make_cors())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fn make_cors() -> cors::Cors {
.expect("To not fail")
}

fn make_rocket() -> rocket::Rocket {
rocket::ignite()
fn make_rocket() -> rocket::Rocket<rocket::Build> {
rocket::build()
.mount("/", routes![cors_responder, panicking_route])
.mount(
"/",
Expand Down
2 changes: 1 addition & 1 deletion tests/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn request_headers(
/// Tests that all the request headers are parsed correcly in a HTTP request
#[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 origin_header = Header::new(ORIGIN.as_str(), "https://foo.bar.xyz");
Expand Down
4 changes: 2 additions & 2 deletions tests/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ fn make_different_cors_options() -> CorsOptions {
}
}

fn rocket() -> rocket::Rocket {
rocket::ignite()
fn rocket() -> rocket::Rocket<rocket::Build> {
rocket::build()
.mount("/", routes![cors, panicking_route])
.mount("/", routes![owned, owned_options])
.mount("/", catch_all_options_routes()) // mount the catch all routes
Expand Down
4 changes: 2 additions & 2 deletions tests/mix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ fn cors_options_all() -> CorsOptions {
Default::default()
}

fn rocket() -> rocket::Rocket {
rocket::ignite()
fn rocket() -> rocket::Rocket<rocket::Build> {
rocket::build()
.mount("/", routes![app, ping, ping_options,])
.mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes
.manage(cors_options().to_cors().expect("Not to fail"))
Expand Down