clippy warnings

This commit is contained in:
Nikolay Kim 2020-04-11 12:23:40 +06:00
parent e58d49570f
commit bdaacaaa08
8 changed files with 52 additions and 62 deletions

View file

@ -5,16 +5,19 @@
[![Build Status](https://github.com/ntex-rs/ntex-extras/workflows/CI%20(Linux)/badge.svg)](https://travis-ci.org/ntex-rs/ntex)
[![Version](https://img.shields.io/badge/rustc-1.42+-lightgray.svg)](https://blog.rust-lang.org/2020/03/12/Rust-1.42.html)
![License](https://img.shields.io/crates/l/ntex-extras.svg)
</p>
</div>
## Crates
| Crate | | |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [ntex-multipart] | [![crates.io](https://img.shields.io/crates/v/ntex-multipart)](https://crates.io/crates/ntex-multipart) [![Documentation](https://docs.rs/ntex-multipart/badge.svg)](https://docs.rs/ntex-multipart) | Multipart support for ntex applications. |
| Crate | | |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------|
| [ntex-cors] | [![crates.io](https://img.shields.io/crates/v/ntex-cors)](https://crates.io/crates/ntex-multipart) [![Documentation](https://docs.rs/ntex-multipart/badge.svg)](https://docs.rs/ntex-cors) | Cors service for ntex applications. |
| [ntex-files] | [![crates.io](https://img.shields.io/crates/v/ntex-files)](https://crates.io/crates/ntex-multipart) [![Documentation](https://docs.rs/ntex-multipart/badge.svg)](https://docs.rs/ntex-files) | Stattic files support for ntex applications. |
| [ntex-identity] | [![crates.io](https://img.shields.io/crates/v/ntex-identity)](https://crates.io/crates/ntex-multipart) [![Documentation](https://docs.rs/ntex-multipart/badge.svg)](https://docs.rs/ntex-idenity) | Identity service for ntex applications. |
| [ntex-multipart] | [![crates.io](https://img.shields.io/crates/v/ntex-multipart)](https://crates.io/crates/ntex-multipart) [![Documentation](https://docs.rs/ntex-multipart/badge.svg)](https://docs.rs/ntex-multipart) | Multipart support for ntex applications. |
| [ntex-session] | [![crates.io](https://img.shields.io/crates/v/ntex-sessioon)](https://crates.io/crates/ntex-multipart) [![Documentation](https://docs.rs/ntex-multipart/badge.svg)](https://docs.rs/ntex-sessioon) | Session service for ntex applications. |
<!-- REFERENCES -->
[ntex-multipart]: ntex-multipart

View file

@ -1,4 +1,8 @@
#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)]
#![allow(
clippy::borrow_interior_mutable_const,
clippy::type_complexity,
clippy::mutable_key_type
)]
//! Cross-origin resource sharing (CORS) for ntex applications
//!
//! CORS middleware could be used with application and with resource.
@ -160,14 +164,12 @@ impl<T> AllOrSome<T> {
/// use ntex_cors::Cors;
/// use ntex::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<Err: ErrorRenderer> {
@ -599,7 +601,7 @@ impl Inner {
AllOrSome::All => Ok(()),
AllOrSome::Some(ref allowed_origins) => allowed_origins
.get(origin)
.and_then(|_| Some(()))
.map(|_| ())
.ok_or_else(|| CorsError::OriginNotAllowed),
};
}
@ -647,7 +649,7 @@ impl Inner {
return self
.methods
.get(&method)
.and_then(|_| Some(()))
.map(|_| ())
.ok_or_else(|| CorsError::MethodNotAllowed);
}
}
@ -804,10 +806,8 @@ where
if let Some(origin) =
inner.access_control_allow_origin(res.request().head())
{
res.headers_mut().insert(
header::ACCESS_CONTROL_ALLOW_ORIGIN,
origin.clone(),
);
res.headers_mut()
.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin);
};
if let Some(ref expose) = inner.expose_hdrs {

View file

@ -19,7 +19,6 @@ use bytes::Bytes;
use futures::future::{ok, ready, Either, FutureExt, LocalBoxFuture, Ready};
use futures::Stream;
use hyperx::header::DispositionType;
use mime;
use mime_guess::from_ext;
use ntex::http::error::BlockingError;
use ntex::http::{header, Method, Payload, Uri};

View file

@ -10,7 +10,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::os::unix::fs::MetadataExt;
use bitflags::bitflags;
use mime;
use mime_guess::from_path;
use futures::future::{ready, Ready};
@ -94,7 +93,7 @@ impl NamedFile {
};
let ct = from_path(&path).first_or_octet_stream();
let disposition_type = match ct.type_() {
let disposition = match ct.type_() {
mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
_ => DispositionType::Attachment,
};
@ -104,8 +103,8 @@ impl NamedFile {
filename.into_owned().into_bytes(),
)];
let cd = ContentDisposition {
disposition: disposition_type,
parameters: parameters,
disposition,
parameters,
};
(ct, cd)
};

View file

@ -35,16 +35,14 @@
//! web::HttpResponse::Ok().finish()
//! }
//!
//! fn main() {
//! let app = web::App::new().wrap(IdentityService::new(
//! // <- create identity middleware
//! CookieIdentityPolicy::new(&[0; 32]) // <- create cookie identity policy
//! .name("auth-cookie")
//! .secure(false)))
//! .service(web::resource("/index.html").to(index))
//! .service(web::resource("/login.html").to(login))
//! .service(web::resource("/logout.html").to(logout));
//! }
//! let app = web::App::new().wrap(IdentityService::new(
//! // <- create identity middleware
//! CookieIdentityPolicy::new(&[0; 32]) // <- create cookie identity policy
//! .name("auth-cookie")
//! .secure(false)))
//! .service(web::resource("/index.html").to(index))
//! .service(web::resource("/login.html").to(login))
//! .service(web::resource("/logout.html").to(logout));
//! ```
use std::convert::Infallible;
use std::future::Future;
@ -206,14 +204,12 @@ pub trait IdentityPolicy<Err>: Sized + 'static {
/// use ntex::web::App;
/// use ntex_identity::{CookieIdentityPolicy, IdentityService};
///
/// fn main() {
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend
/// .name("auth-cookie")
/// .secure(false),
/// ));
/// }
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend
/// .name("auth-cookie")
/// .secure(false),
/// ));
/// ```
pub struct IdentityService<T, Err> {
backend: Rc<T>,
@ -487,16 +483,14 @@ impl<Err: ErrorRenderer> CookieIdentityInner<Err> {
/// use ntex::web::App;
/// use ntex_identity::{CookieIdentityPolicy, IdentityService};
///
/// fn main() {
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- construct cookie policy
/// .domain("www.rust-lang.org")
/// .name("ntex-auth")
/// .path("/")
/// .secure(true),
/// ));
/// }
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- construct cookie policy
/// .domain("www.rust-lang.org")
/// .name("ntex-auth")
/// .path("/")
/// .secure(true),
/// ));
/// ```
pub struct CookieIdentityPolicy<Err>(Rc<CookieIdentityInner<Err>>);

View file

@ -9,8 +9,6 @@ use std::{cmp, fmt};
use bytes::{Bytes, BytesMut};
use futures::stream::{LocalBoxStream, Stream, StreamExt};
use httparse;
use mime;
use ntex::http::error::{ParseError, PayloadError};
use ntex::http::header::{self, HeaderMap, HeaderName, HeaderValue};
@ -862,7 +860,7 @@ mod tests {
impl SlowStream {
fn new(bytes: Bytes) -> SlowStream {
return SlowStream {
bytes: bytes,
bytes,
pos: 0,
ready: false,
};

View file

@ -92,7 +92,7 @@ impl<Err> CookieSessionInner<Err> {
let value =
serde_json::to_string(&state).map_err(CookieSessionError::Serialize)?;
if value.len() > 4064 {
return Err(CookieSessionError::Overflow.into());
return Err(CookieSessionError::Overflow);
}
let mut cookie = Cookie::new(self.name.clone(), value);
@ -201,15 +201,13 @@ impl<Err> CookieSessionInner<Err> {
/// use ntex_session::CookieSession;
/// use ntex::web::{self, App, HttpResponse, HttpServer};
///
/// fn main() {
/// let app = App::new().wrap(
/// CookieSession::signed(&[0; 32])
/// .domain("www.rust-lang.org")
/// .name("ntex-session")
/// .path("/")
/// .secure(true))
/// .service(web::resource("/").to(|| async { HttpResponse::Ok() }));
/// }
/// let app = App::new().wrap(
/// CookieSession::signed(&[0; 32])
/// .domain("www.rust-lang.org")
/// .name("ntex-session")
/// .path("/")
/// .secure(true))
/// .service(web::resource("/").to(|| async { HttpResponse::Ok() }));
/// ```
pub struct CookieSession<Err>(Rc<CookieSessionInner<Err>>);
@ -353,11 +351,11 @@ where
/// session state changes, then set-cookie is returned in response. As
/// a user logs out, call session.purge() to set SessionStatus accordingly
/// and this will trigger removal of the session cookie in the response.
fn call(&self, mut req: WebRequest<Err>) -> Self::Future {
fn call(&self, req: WebRequest<Err>) -> Self::Future {
let inner = self.inner.clone();
let (is_new, state) = self.inner.load(&req);
let prolong_expiration = self.inner.expires_in.is_some();
Session::set_session(state.into_iter(), &mut req);
Session::set_session(state.into_iter(), &req);
let fut = self.service.call(req);

View file

@ -52,7 +52,6 @@ use ntex::web::dev::{WebRequest, WebResponse};
use ntex::web::{Error, FromRequest, HttpRequest};
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_json;
#[cfg(feature = "cookie-session")]
mod cookie;