diff --git a/README.md b/README.md index 515a1c89..96e74039 100644 --- a/README.md +++ b/README.md @@ -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)

## 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. | [ntex-multipart]: ntex-multipart diff --git a/ntex-cors/src/lib.rs b/ntex-cors/src/lib.rs index d431e2bf..d6e14ae9 100644 --- a/ntex-cors/src/lib.rs +++ b/ntex-cors/src/lib.rs @@ -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 AllOrSome { /// 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 { @@ -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 { diff --git a/ntex-files/src/lib.rs b/ntex-files/src/lib.rs index 1514dd52..f7b8934d 100644 --- a/ntex-files/src/lib.rs +++ b/ntex-files/src/lib.rs @@ -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}; diff --git a/ntex-files/src/named.rs b/ntex-files/src/named.rs index a56e4ccf..70a16ee2 100644 --- a/ntex-files/src/named.rs +++ b/ntex-files/src/named.rs @@ -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) }; diff --git a/ntex-identity/src/lib.rs b/ntex-identity/src/lib.rs index 021ba557..ca232624 100644 --- a/ntex-identity/src/lib.rs +++ b/ntex-identity/src/lib.rs @@ -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: 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 { backend: Rc, @@ -487,16 +483,14 @@ impl CookieIdentityInner { /// 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(Rc>); diff --git a/ntex-multipart/src/server.rs b/ntex-multipart/src/server.rs index 4f0d2ec1..f1c6df82 100644 --- a/ntex-multipart/src/server.rs +++ b/ntex-multipart/src/server.rs @@ -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, }; diff --git a/ntex-session/src/cookie.rs b/ntex-session/src/cookie.rs index 35093653..fd391cd2 100644 --- a/ntex-session/src/cookie.rs +++ b/ntex-session/src/cookie.rs @@ -92,7 +92,7 @@ impl CookieSessionInner { 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 CookieSessionInner { /// 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(Rc>); @@ -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) -> Self::Future { + fn call(&self, req: WebRequest) -> 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); diff --git a/ntex-session/src/lib.rs b/ntex-session/src/lib.rs index e8f13494..07bb1fc4 100644 --- a/ntex-session/src/lib.rs +++ b/ntex-session/src/lib.rs @@ -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;