Update library to 0.4 and support Rocket 0.4 (#46)

* Update Cargo.toml for Rocket `master`

* Prepare library for Rocket 0.4

TODO: check line 62 in `fairing.rs` to find better way than unwrapping

* Bump minimum nightly for Rocket 0.4
This commit is contained in:
Eric Dattore 2018-10-30 20:25:10 -06:00 committed by Yong Wen Chua
parent 351f0f945f
commit 0b73773692
15 changed files with 43 additions and 65 deletions

View File

@ -3,7 +3,7 @@ language: rust
rust:
- nightly
# Minimum Rust set by Rocket
- nightly-2018-08-24
- nightly-2018-10-06
branches:
only:
- master

View File

@ -1,6 +1,6 @@
[package]
name = "rocket_cors"
version = "0.3.0"
version = "0.4.0"
license = "MIT/Apache-2.0"
authors = ["Yong Wen Chua <me@yongwen.xyz>"]
description = "Cross-origin resource sharing (CORS) for Rocket.rs applications"
@ -20,8 +20,8 @@ default = ["serialization"]
serialization = ["serde", "serde_derive", "unicase_serde", "url_serde"]
[dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "master" }
log = "0.3"
rocket = "0.3.16"
unicase = "2.0"
url = "1.5.1"
@ -33,7 +33,6 @@ url_serde = { version = "0.2.0", optional = true }
[dev-dependencies]
hyper = "0.10"
rocket_codegen = "0.3.16"
serde_json = "1.0"
serde_test = "1.0"

View File

@ -1,6 +1,5 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use rocket::http::Method;

View File

@ -1,6 +1,5 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use std::io::Cursor;

View File

@ -1,6 +1,7 @@
//! This example is to demonstrate the JSON serialization and deserialization of the Cors settings
//!
//! Note: This requires the `serialization` feature which is enabled by default.
#![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket;
extern crate rocket_cors as cors;
extern crate serde_json;

View File

@ -1,6 +1,5 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use std::io::Cursor;

View File

@ -3,9 +3,8 @@
//! In this example, you typically have an application wide `Cors` struct except for one specific
//! `ping` route that you want to allow all Origins to access.
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use rocket::http::Method;

View File

@ -1,7 +1,7 @@
//! Fairing implementation
use std::str::FromStr;
use rocket::http::{self, Header, Status};
use rocket::http::{self, Header, Status, uri::Origin};
use rocket::{self, Outcome, Request};
use {actual_request_response, origin, preflight_response, request_headers, validate, Cors, Error};
@ -44,7 +44,7 @@ pub(crate) fn fairing_error_route<'r>(
request: &'r Request,
_: rocket::Data,
) -> rocket::handler::Outcome<'r> {
let status = request.get_param::<u16>(0).unwrap_or_else(|e| {
let status = request.get_param::<u16>(0).unwrap_or(Ok(0)).unwrap_or_else(|e| {
error_!("Fairing Error Handling Route error: {:?}", e);
500
});
@ -59,8 +59,10 @@ fn fairing_route(rank: isize) -> rocket::Route {
/// Modifies a `Request` to route to Fairing error handler
fn route_to_fairing_error_handler(options: &Cors, status: u16, request: &mut Request) {
let origin = Origin::parse_owned(format!("{}/{}", options.fairing_route_base, status)).unwrap();
request.set_method(http::Method::Get);
request.set_uri(format!("{}/{}", options.fairing_route_base, status));
request.set_uri(origin);
}
/// Inject a header into the Request with result
@ -217,7 +219,7 @@ mod tests {
let expected_uri = format!("{}/<status>", CORS_ROOT);
let error_route = rocket
.routes()
.find(|r| r.method == Method::Get && r.uri.as_str() == expected_uri);
.find(|r| r.method == Method::Get && r.uri.to_string() == expected_uri);
assert!(error_route.is_some());
}

View File

@ -120,7 +120,7 @@ pub type Origin = Url;
pub struct AccessControlRequestMethod(pub ::Method);
impl FromStr for AccessControlRequestMethod {
type Err = rocket::Error;
type Err = ();
fn from_str(method: &str) -> Result<Self, Self::Err> {
Ok(AccessControlRequestMethod(::Method::from_str(method)?))
@ -134,7 +134,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestMethod {
match request.headers().get_one("Access-Control-Request-Method") {
Some(request_method) => match Self::from_str(request_method) {
Ok(request_method) => Outcome::Success(request_method),
Err(e) => Outcome::Failure((Status::BadRequest, ::Error::BadRequestMethod(e))),
Err(_) => Outcome::Failure((Status::BadRequest, ::Error::BadRequestMethod)),
},
None => Outcome::Forward(()),
}

View File

@ -101,9 +101,8 @@
//! [`attach`](https://api.rocket.rs/rocket/struct.Rocket.html#method.attach) it to Rocket.
//!
//! ```rust,no_run
//! #![feature(plugin, custom_derive)]
//! #![plugin(rocket_codegen)]
//! extern crate rocket;
//! #![feature(proc_macro_hygiene, decl_macro)]
//! #[macro_use] extern crate rocket;
//! extern crate rocket_cors;
//!
//! use rocket::http::Method;
@ -176,9 +175,8 @@
//! [`Guard`](Guard) for a `Response` or a `Responder`.
//!
//! ```rust,no_run
//! #![feature(plugin)]
//! #![plugin(rocket_codegen)]
//! extern crate rocket;
//! #![feature(proc_macro_hygiene, decl_macro)]
//! #[macro_use] extern crate rocket;
//! extern crate rocket_cors;
//!
//! use std::io::Cursor;
@ -295,9 +293,8 @@
//! (which you might have put in Rocket's state).
//!
//! ```rust,no_run
//! #![feature(plugin)]
//! #![plugin(rocket_codegen)]
//! extern crate rocket;
//! #![feature(proc_macro_hygiene, decl_macro)]
//! #[macro_use] extern crate rocket;
//! extern crate rocket_cors;
//!
//! use rocket::http::Method;
@ -352,9 +349,8 @@
//! special handling, you might want to use the Guard method instead which has less hassle.
//!
//! ```rust,no_run
//! #![feature(plugin)]
//! #![plugin(rocket_codegen)]
//! extern crate rocket;
//! #![feature(proc_macro_hygiene, decl_macro)]
//! #[macro_use] extern crate rocket;
//! extern crate rocket_cors;
//!
//! use std::io::Cursor;
@ -421,9 +417,8 @@
//! You can run the example code below with `cargo run --example mix`.
//!
//! ```rust,no_run
//! #![feature(plugin)]
//! #![plugin(rocket_codegen)]
//! extern crate rocket;
//! #![feature(proc_macro_hygiene, decl_macro)]
//! #[macro_use] extern crate rocket;
//! extern crate rocket_cors;
//!
//! use rocket::http::Method;
@ -516,8 +511,6 @@
overflowing_literals,
path_statements,
plugin_as_library,
private_no_mangle_fns,
private_no_mangle_statics,
stable_features,
trivial_casts,
trivial_numeric_casts,
@ -538,7 +531,6 @@
unused_parens,
unused_results,
unused_unsafe,
unused_variables,
variant_size_differences,
warnings,
while_true
@ -551,8 +543,6 @@
unsafe_code,
intra_doc_link_resolution_failure
)]
#![cfg_attr(test, feature(plugin))]
#![cfg_attr(test, plugin(rocket_codegen))]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#[macro_use]
@ -622,7 +612,7 @@ pub enum Error {
/// The request header `Access-Control-Request-Method` is required but is missing
MissingRequestMethod,
/// The request header `Access-Control-Request-Method` has an invalid value
BadRequestMethod(rocket::Error),
BadRequestMethod,
/// The request header `Access-Control-Request-Headers` is required but is missing.
MissingRequestHeaders,
/// Origin is not allowed to make this request
@ -672,7 +662,7 @@ impl error::Error for Error {
"The request header `Access-Control-Request-Method` \
is required but is missing"
}
Error::BadRequestMethod(_) => {
Error::BadRequestMethod => {
"The request header `Access-Control-Request-Method` has an invalid value"
}
Error::MissingRequestHeaders => {
@ -712,7 +702,6 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::BadOrigin(ref e) => fmt::Display::fmt(e, f),
Error::BadRequestMethod(ref e) => fmt::Debug::fmt(e, f),
_ => write!(f, "{}", error::Error::description(self)),
}
}
@ -780,7 +769,7 @@ impl AllOrSome<HashSet<Url>> {
pub struct Method(http::Method);
impl FromStr for Method {
type Err = rocket::Error;
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let method = http::Method::from_str(s)?;

View File

@ -1,9 +1,7 @@
//! This crate tests using `rocket_cors` using Fairings
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper;
extern crate rocket;
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use std::str::FromStr;

View File

@ -1,9 +1,7 @@
//! This crate tests using `rocket_cors` using the per-route handling with request guard
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper;
extern crate rocket;
#[macro_use] extern crate rocket;
extern crate rocket_cors as cors;
use std::str::FromStr;

View File

@ -1,8 +1,7 @@
//! This crate tests that all the request headers are parsed correctly in the round trip
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper;
extern crate rocket;
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use std::ops::Deref;

View File

@ -1,9 +1,7 @@
//! This crate tests using `rocket_cors` using manual mode
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper;
extern crate rocket;
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use std::str::FromStr;

View File

@ -2,11 +2,9 @@
//!
//! In this example, you typically have an application wide `Cors` struct except for one specific
//! `ping` route that you want to allow all Origins to access.
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper;
extern crate rocket;
#[macro_use] extern crate rocket;
extern crate rocket_cors;
use std::str::FromStr;