Cargo clippy fixes
This commit is contained in:
parent
198190fb08
commit
ede4b1a222
8
build.rs
8
build.rs
|
@ -44,13 +44,13 @@ fn main() {
|
||||||
printerr!(
|
printerr!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
Red.bold().paint("Error:"),
|
Red.bold().paint("Error:"),
|
||||||
White.paint("rowdy requires a nightly version of Rust.")
|
White.paint("rocket_cors requires a nightly version of Rust.")
|
||||||
);
|
);
|
||||||
print_version_err(&*version, &*date);
|
print_version_err(&*version, &*date);
|
||||||
printerr!(
|
printerr!(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
Blue.paint("See the README ("),
|
Blue.paint("See the README ("),
|
||||||
White.paint("https://github.com/lawliet89/rowdy"),
|
White.paint("https://github.com/lawliet89/rocket_cors"),
|
||||||
Blue.paint(") for more information.")
|
Blue.paint(") for more information.")
|
||||||
);
|
);
|
||||||
panic!("Aborting compilation due to incompatible compiler.")
|
panic!("Aborting compilation due to incompatible compiler.")
|
||||||
|
@ -60,7 +60,7 @@ fn main() {
|
||||||
printerr!(
|
printerr!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
Red.bold().paint("Error:"),
|
Red.bold().paint("Error:"),
|
||||||
White.paint("rowdy requires a more recent version of rustc.")
|
White.paint("rocket_cors requires a more recent version of rustc.")
|
||||||
);
|
);
|
||||||
printerr!(
|
printerr!(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
|
@ -75,7 +75,7 @@ fn main() {
|
||||||
_ => {
|
_ => {
|
||||||
println!(
|
println!(
|
||||||
"cargo:warning={}",
|
"cargo:warning={}",
|
||||||
"rowdy was unable to check rustc compatibility."
|
"rocket_cors was unable to check rustc compatibility."
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"cargo:warning={}",
|
"cargo:warning={}",
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
//! Fairing implementation
|
//! Fairing implementation
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use rocket::{self, Request, Outcome};
|
use rocket::{self, Request, Outcome};
|
||||||
use rocket::http::{self, Status, Header};
|
use rocket::http::{self, Status, Header};
|
||||||
|
|
||||||
|
@ -18,7 +20,10 @@ impl InjectedHeader {
|
||||||
InjectedHeader::Failure => "Failure",
|
InjectedHeader::Failure => "Failure",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for InjectedHeader {
|
||||||
|
type Err = Error;
|
||||||
fn from_str(s: &str) -> Result<Self, Error> {
|
fn from_str(s: &str) -> Result<Self, Error> {
|
||||||
match s {
|
match s {
|
||||||
"Success" => Ok(InjectedHeader::Success),
|
"Success" => Ok(InjectedHeader::Success),
|
||||||
|
@ -59,7 +64,7 @@ fn route_to_fairing_error_handler(options: &Cors, status: u16, request: &mut Req
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inject a header into the Request with result
|
/// Inject a header into the Request with result
|
||||||
fn inject_request_header(header: InjectedHeader, request: &mut Request) {
|
fn inject_request_header(header: &InjectedHeader, request: &mut Request) {
|
||||||
request.replace_header(Header::new(CORS_HEADER, header.to_str()));
|
request.replace_header(Header::new(CORS_HEADER, header.to_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,9 +94,9 @@ fn on_response_wrapper(
|
||||||
|
|
||||||
let cors_response = if request.method() == http::Method::Options {
|
let cors_response = if request.method() == http::Method::Options {
|
||||||
let headers = request_headers(request)?;
|
let headers = request_headers(request)?;
|
||||||
preflight_response(options, origin, headers)
|
preflight_response(options, &origin, headers.as_ref())
|
||||||
} else {
|
} else {
|
||||||
actual_request_response(options, origin)
|
actual_request_response(options, &origin)
|
||||||
};
|
};
|
||||||
|
|
||||||
cors_response.merge(response);
|
cors_response.merge(response);
|
||||||
|
@ -147,7 +152,7 @@ impl rocket::fairing::Fairing for Cors {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inject_request_header(injected_header, request);
|
inject_request_header(&injected_header, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_response(&self, request: &Request, response: &mut rocket::Response) {
|
fn on_response(&self, request: &Request, response: &mut rocket::Response) {
|
||||||
|
|
36
src/lib.rs
36
src/lib.rs
|
@ -1403,9 +1403,9 @@ fn validate_and_build(options: &Cors, request: &Request) -> Result<Response, Err
|
||||||
Ok(match result {
|
Ok(match result {
|
||||||
ValidationResult::None => Response::new(),
|
ValidationResult::None => Response::new(),
|
||||||
ValidationResult::Preflight { origin, headers } => {
|
ValidationResult::Preflight { origin, headers } => {
|
||||||
preflight_response(options, origin, headers)
|
preflight_response(options, &origin, headers.as_ref())
|
||||||
}
|
}
|
||||||
ValidationResult::Request { origin } => actual_request_response(options, origin),
|
ValidationResult::Request { origin } => actual_request_response(options, &origin),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1532,7 +1532,7 @@ fn preflight_validate(
|
||||||
|
|
||||||
// 2. If the value of the Origin header is not a case-sensitive match for any of the values
|
// 2. If the value of the Origin header is not a case-sensitive match for any of the values
|
||||||
// in list of origins do not set any additional headers and terminate this set of steps.
|
// in list of origins do not set any additional headers and terminate this set of steps.
|
||||||
validate_origin(&origin, &options.allowed_origins)?;
|
validate_origin(origin, &options.allowed_origins)?;
|
||||||
|
|
||||||
// 3. Let `method` be the value as result of parsing the Access-Control-Request-Method
|
// 3. Let `method` be the value as result of parsing the Access-Control-Request-Method
|
||||||
// header.
|
// header.
|
||||||
|
@ -1558,7 +1558,7 @@ fn preflight_validate(
|
||||||
// values in list of headers do not set any additional headers and terminate this set of
|
// values in list of headers do not set any additional headers and terminate this set of
|
||||||
// steps.
|
// steps.
|
||||||
|
|
||||||
if let &Some(ref headers) = headers {
|
if let Some(ref headers) = *headers {
|
||||||
validate_allowed_headers(headers, &options.allowed_headers)?;
|
validate_allowed_headers(headers, &options.allowed_headers)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1571,8 +1571,8 @@ fn preflight_validate(
|
||||||
/// [W3C recommendation](https://www.w3.org/TR/cors/#resource-preflight-requests).
|
/// [W3C recommendation](https://www.w3.org/TR/cors/#resource-preflight-requests).
|
||||||
fn preflight_response(
|
fn preflight_response(
|
||||||
options: &Cors,
|
options: &Cors,
|
||||||
origin: Origin,
|
origin: &Origin,
|
||||||
headers: Option<AccessControlRequestHeaders>,
|
headers: Option<&AccessControlRequestHeaders>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let response = Response::new();
|
let response = Response::new();
|
||||||
|
|
||||||
|
@ -1590,10 +1590,10 @@ fn preflight_response(
|
||||||
if options.send_wildcard {
|
if options.send_wildcard {
|
||||||
response.any()
|
response.any()
|
||||||
} else {
|
} else {
|
||||||
response.origin(&origin, true)
|
response.origin(origin, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AllOrSome::Some(_) => response.origin(&origin, false),
|
AllOrSome::Some(_) => response.origin(origin, false),
|
||||||
};
|
};
|
||||||
let response = response.credentials(options.allow_credentials);
|
let response = response.credentials(options.allow_credentials);
|
||||||
|
|
||||||
|
@ -1623,7 +1623,7 @@ fn preflight_response(
|
||||||
// from Access-Control-Allow-Headers can be enough.
|
// from Access-Control-Allow-Headers can be enough.
|
||||||
|
|
||||||
// We do not do anything special with simple headers
|
// We do not do anything special with simple headers
|
||||||
let response = if let Some(ref headers) = headers {
|
if let Some(headers) = headers {
|
||||||
let &AccessControlRequestHeaders(ref headers) = headers;
|
let &AccessControlRequestHeaders(ref headers) = headers;
|
||||||
response.headers(
|
response.headers(
|
||||||
headers
|
headers
|
||||||
|
@ -1634,9 +1634,7 @@ fn preflight_response(
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
response
|
response
|
||||||
};
|
}
|
||||||
|
|
||||||
response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Do checks for an actual request
|
/// Do checks for an actual request
|
||||||
|
@ -1652,7 +1650,7 @@ fn actual_request_validate(options: &Cors, origin: &Origin) -> Result<(), Error>
|
||||||
// in list of origins, do not set any additional headers and terminate this set of steps.
|
// in list of origins, do not set any additional headers and terminate this set of steps.
|
||||||
// Always matching is acceptable since the list of origins can be unbounded.
|
// Always matching is acceptable since the list of origins can be unbounded.
|
||||||
|
|
||||||
validate_origin(&origin, &options.allowed_origins)?;
|
validate_origin(origin, &options.allowed_origins)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1661,7 +1659,7 @@ fn actual_request_validate(options: &Cors, origin: &Origin) -> Result<(), Error>
|
||||||
///
|
///
|
||||||
/// This implementation references the
|
/// This implementation references the
|
||||||
/// [W3C recommendation](https://www.w3.org/TR/cors/#resource-requests).
|
/// [W3C recommendation](https://www.w3.org/TR/cors/#resource-requests).
|
||||||
fn actual_request_response(options: &Cors, origin: Origin) -> Response {
|
fn actual_request_response(options: &Cors, origin: &Origin) -> Response {
|
||||||
let response = Response::new();
|
let response = Response::new();
|
||||||
|
|
||||||
// 3. If the resource supports credentials add a single Access-Control-Allow-Origin header,
|
// 3. If the resource supports credentials add a single Access-Control-Allow-Origin header,
|
||||||
|
@ -1679,10 +1677,10 @@ fn actual_request_response(options: &Cors, origin: Origin) -> Response {
|
||||||
if options.send_wildcard {
|
if options.send_wildcard {
|
||||||
response.any()
|
response.any()
|
||||||
} else {
|
} else {
|
||||||
response.origin(&origin, true)
|
response.origin(origin, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AllOrSome::Some(_) => response.origin(&origin, false),
|
AllOrSome::Some(_) => response.origin(origin, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = response.credentials(options.allow_credentials);
|
let response = response.credentials(options.allow_credentials);
|
||||||
|
@ -1694,16 +1692,14 @@ fn actual_request_response(options: &Cors, origin: Origin) -> Response {
|
||||||
// of all entries where origin is a case-sensitive match for the value of the Origin header
|
// of all entries where origin is a case-sensitive match for the value of the Origin header
|
||||||
// and url is a case-sensitive match for the URL of the resource.
|
// and url is a case-sensitive match for the URL of the resource.
|
||||||
|
|
||||||
let response = response.exposed_headers(
|
response.exposed_headers(
|
||||||
options
|
options
|
||||||
.expose_headers
|
.expose_headers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| &**s)
|
.map(|s| &**s)
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.as_slice(),
|
.as_slice(),
|
||||||
);
|
)
|
||||||
|
|
||||||
response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns "catch all" OPTIONS routes that you can mount to catch all OPTIONS request. Only works
|
/// Returns "catch all" OPTIONS routes that you can mount to catch all OPTIONS request. Only works
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! This crate tests using rocket_cors using Fairings
|
//! This crate tests using `rocket_cors` using Fairings
|
||||||
|
|
||||||
#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! This crate tests using rocket_cors using the per-route handling with request guard
|
//! This crate tests using `rocket_cors` using the per-route handling with request guard
|
||||||
|
|
||||||
#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! This crate tests using rocket_cors using manual mode
|
//! This crate tests using `rocket_cors` using manual mode
|
||||||
|
|
||||||
#![feature(plugin, conservative_impl_trait)]
|
#![feature(plugin, conservative_impl_trait)]
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
Loading…
Reference in New Issue