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

View File

@ -134,6 +134,7 @@ where
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
#[allow(clippy::type_complexity)]
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
@ -266,7 +267,7 @@ impl Inner {
value: Option<String>,
) -> Result<ServiceResponse<B>, Error> {
let (value, jar) = if let Some(value) = value {
(value.clone(), None)
(value, None)
} else {
let value: String = iter::repeat(())
.map(|()| OsRng.sample(Alphanumeric))
@ -559,7 +560,7 @@ mod test {
.unwrap();
assert_eq!(
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();
@ -618,7 +619,7 @@ mod test {
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
// - set-cookie actix-session will be in response with session cookie #2
@ -632,7 +633,7 @@ mod test {
.into_iter()
.find(|c| c.name() == "test-session")
.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
// - set-cookie actix-session will be in response (session cookie #3)
@ -655,6 +656,6 @@ mod test {
.into_iter()
.find(|c| c.name() == "test-session")
.unwrap();
assert!(cookie_5.value().to_string() != cookie_2.value().to_string());
assert!(cookie_5.value() != cookie_2.value());
}
}