1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-03-20 20:05:18 +01:00

Fix/suppress clippy warnings

This commit is contained in:
Yuki Okushi 2020-01-30 18:21:02 +09:00
parent d8f3f94ece
commit 21994c13eb
2 changed files with 10 additions and 10 deletions

View File

@ -160,14 +160,12 @@ impl<T> AllOrSome<T> {
/// use actix_cors::Cors; /// use actix_cors::Cors;
/// use actix_web::http::header; /// use actix_web::http::header;
/// ///
/// # fn main() {
/// let cors = Cors::new() /// let cors = Cors::new()
/// .allowed_origin("https://www.rust-lang.org/") /// .allowed_origin("https://www.rust-lang.org/")
/// .allowed_methods(vec!["GET", "POST"]) /// .allowed_methods(vec!["GET", "POST"])
/// .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT]) /// .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
/// .allowed_header(header::CONTENT_TYPE) /// .allowed_header(header::CONTENT_TYPE)
/// .max_age(3600); /// .max_age(3600);
/// # }
/// ``` /// ```
#[derive(Default)] #[derive(Default)]
pub struct Cors { pub struct Cors {
@ -585,7 +583,7 @@ impl Inner {
AllOrSome::All => Ok(()), AllOrSome::All => Ok(()),
AllOrSome::Some(ref allowed_origins) => allowed_origins AllOrSome::Some(ref allowed_origins) => allowed_origins
.get(origin) .get(origin)
.and_then(|_| Some(())) .map(|_| ())
.ok_or_else(|| CorsError::OriginNotAllowed), .ok_or_else(|| CorsError::OriginNotAllowed),
}; };
} }
@ -633,7 +631,7 @@ impl Inner {
return self return self
.methods .methods
.get(&method) .get(&method)
.and_then(|_| Some(())) .map(|_| ())
.ok_or_else(|| CorsError::MethodNotAllowed); .ok_or_else(|| CorsError::MethodNotAllowed);
} }
} }
@ -651,6 +649,7 @@ impl Inner {
req.headers().get(&header::ACCESS_CONTROL_REQUEST_HEADERS) req.headers().get(&header::ACCESS_CONTROL_REQUEST_HEADERS)
{ {
if let Ok(headers) = hdr.to_str() { if let Ok(headers) = hdr.to_str() {
#[allow(clippy::mutable_key_type)] // FIXME: revisit here
let mut hdrs = HashSet::new(); let mut hdrs = HashSet::new();
for hdr in headers.split(',') { for hdr in headers.split(',') {
match HeaderName::try_from(hdr.trim()) { match HeaderName::try_from(hdr.trim()) {
@ -779,7 +778,7 @@ where
{ {
res.headers_mut().insert( res.headers_mut().insert(
header::ACCESS_CONTROL_ALLOW_ORIGIN, header::ACCESS_CONTROL_ALLOW_ORIGIN,
origin.clone(), origin,
); );
}; };

View File

@ -134,6 +134,7 @@ where
type Request = ServiceRequest; type Request = ServiceRequest;
type Response = ServiceResponse<B>; type Response = ServiceResponse<B>;
type Error = Error; type Error = Error;
#[allow(clippy::type_complexity)]
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>; type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
@ -266,7 +267,7 @@ impl Inner {
value: Option<String>, value: Option<String>,
) -> Result<ServiceResponse<B>, Error> { ) -> Result<ServiceResponse<B>, Error> {
let (value, jar) = if let Some(value) = value { let (value, jar) = if let Some(value) = value {
(value.clone(), None) (value, None)
} else { } else {
let value: String = iter::repeat(()) let value: String = iter::repeat(())
.map(|()| OsRng.sample(Alphanumeric)) .map(|()| OsRng.sample(Alphanumeric))
@ -559,7 +560,7 @@ mod test {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
true, true,
cookie_1.value().to_string() != cookie_2.value().to_string() cookie_1.value() != cookie_2.value()
); );
let result_5 = resp_5.json::<IndexResponse>().await.unwrap(); let result_5 = resp_5.json::<IndexResponse>().await.unwrap();
@ -618,7 +619,7 @@ mod test {
counter: 0 counter: 0
} }
); );
assert!(cookie_3.value().to_string() != cookie_2.value().to_string()); assert!(cookie_3.value() != cookie_2.value());
// Step 9: POST to logout, including session cookie #2 // Step 9: POST to logout, including session cookie #2
// - set-cookie actix-session will be in response with session cookie #2 // - set-cookie actix-session will be in response with session cookie #2
@ -632,7 +633,7 @@ mod test {
.into_iter() .into_iter()
.find(|c| c.name() == "test-session") .find(|c| c.name() == "test-session")
.unwrap(); .unwrap();
assert!(&time::now().tm_year != &cookie_4.expires().map(|t| t.tm_year).unwrap()); assert_ne!(time::now().tm_year, cookie_4.expires().map(|t| t.tm_year).unwrap());
// Step 10: GET index, including session cookie #2 in request // Step 10: GET index, including session cookie #2 in request
// - set-cookie actix-session will be in response (session cookie #3) // - set-cookie actix-session will be in response (session cookie #3)
@ -655,6 +656,6 @@ mod test {
.into_iter() .into_iter()
.find(|c| c.name() == "test-session") .find(|c| c.name() == "test-session")
.unwrap(); .unwrap();
assert!(cookie_5.value().to_string() != cookie_2.value().to_string()); assert!(cookie_5.value() != cookie_2.value());
} }
} }