diff --git a/Cargo.toml b/Cargo.toml index d781422ee..470644e0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ rust-tls = ["rustls", "actix-server/rust-tls"] [dependencies] actix-codec = "0.1.2" actix-service = "0.4.1" -actix-utils = "0.4.3" +actix-utils = "0.4.4" actix-router = "0.1.5" actix-rt = "0.2.4" actix-web-codegen = "0.1.2" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 516793264..84033531d 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,11 +1,14 @@ # Changes -## [0.2.6] - TBD +## [0.2.6] - 2019-07-17 ### Changed +* Replace `ClonableService` with local copy + * Upgrade `rand` dependency version to 0.7 + ## [0.2.5] - 2019-06-28 ### Added diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 5db7a6ca3..e922c86d9 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -46,10 +46,10 @@ secure-cookies = ["ring"] [dependencies] actix-service = "0.4.1" actix-codec = "0.1.2" -actix-connect = "0.2.0" -actix-utils = "0.4.2" +actix-connect = "0.2.1" +actix-utils = "0.4.4" actix-server-config = "0.1.1" -actix-threadpool = "0.1.0" +actix-threadpool = "0.1.1" base64 = "0.10" bitflags = "1.0" diff --git a/actix-http/src/client/connector.rs b/actix-http/src/client/connector.rs index 0241e8472..cd3ae3d9e 100644 --- a/actix-http/src/client/connector.rs +++ b/actix-http/src/client/connector.rs @@ -47,6 +47,7 @@ pub struct Connector { } impl Connector<(), ()> { + #[allow(clippy::new_ret_no_self)] pub fn new() -> Connector< impl Service< Request = TcpConnect, diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 8dedf72f5..4739141d0 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -427,7 +427,9 @@ where fn check_availibility(&self) { if !self.waiters_queue.is_empty() && self.acquired < self.limit { - self.task.as_ref().map(|t| t.notify()); + if let Some(t) = self.task.as_ref() { + t.notify() + } } } } diff --git a/actix-http/src/cloneable.rs b/actix-http/src/cloneable.rs new file mode 100644 index 000000000..ffc1d0611 --- /dev/null +++ b/actix-http/src/cloneable.rs @@ -0,0 +1,42 @@ +use std::cell::UnsafeCell; +use std::rc::Rc; + +use actix_service::Service; +use futures::Poll; + +#[doc(hidden)] +/// Service that allows to turn non-clone service to a service with `Clone` impl +pub(crate) struct CloneableService(Rc>); + +impl CloneableService { + pub(crate) fn new(service: T) -> Self + where + T: Service, + { + Self(Rc::new(UnsafeCell::new(service))) + } +} + +impl Clone for CloneableService { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + +impl Service for CloneableService +where + T: Service, +{ + type Request = T::Request; + type Response = T::Response; + type Error = T::Error; + type Future = T::Future; + + fn poll_ready(&mut self) -> Poll<(), Self::Error> { + unsafe { &mut *self.0.as_ref().get() }.poll_ready() + } + + fn call(&mut self, req: T::Request) -> Self::Future { + unsafe { &mut *self.0.as_ref().get() }.call(req) + } +} diff --git a/actix-http/src/cookie/mod.rs b/actix-http/src/cookie/mod.rs index ddcb12bbf..f576a4521 100644 --- a/actix-http/src/cookie/mod.rs +++ b/actix-http/src/cookie/mod.rs @@ -104,6 +104,7 @@ impl CookieStr { } } + #[allow(clippy::ptr_arg)] fn to_raw_str<'s, 'c: 's>(&'s self, string: &'s Cow<'c, str>) -> Option<&'c str> { match *self { CookieStr::Indexed(i, j) => match *string { diff --git a/actix-http/src/cookie/secure/key.rs b/actix-http/src/cookie/secure/key.rs index 4e74f6e78..8435ce3ab 100644 --- a/actix-http/src/cookie/secure/key.rs +++ b/actix-http/src/cookie/secure/key.rs @@ -7,7 +7,7 @@ use super::private::KEY_LEN as PRIVATE_KEY_LEN; use super::signed::KEY_LEN as SIGNED_KEY_LEN; static HKDF_DIGEST: &'static Algorithm = &SHA256; -const KEYS_INFO: &'static str = "COOKIE;SIGNED:HMAC-SHA256;PRIVATE:AEAD-AES-256-GCM"; +const KEYS_INFO: &str = "COOKIE;SIGNED:HMAC-SHA256;PRIVATE:AEAD-AES-256-GCM"; /// A cryptographic master key for use with `Signed` and/or `Private` jars. /// diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 91990d05c..5e9c0b53d 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -5,7 +5,6 @@ use std::{fmt, io, net}; use actix_codec::{Decoder, Encoder, Framed, FramedParts}; use actix_server_config::IoStream; use actix_service::Service; -use actix_utils::cloneable::CloneableService; use bitflags::bitflags; use bytes::{BufMut, BytesMut}; use futures::{Async, Future, Poll}; @@ -13,6 +12,7 @@ use log::{error, trace}; use tokio_timer::Delay; use crate::body::{Body, BodySize, MessageBody, ResponseBody}; +use crate::cloneable::CloneableService; use crate::config::ServiceConfig; use crate::error::{DispatchError, Error}; use crate::error::{ParseError, PayloadError}; diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index 192d1b598..108b7079e 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -5,11 +5,11 @@ use std::rc::Rc; use actix_codec::Framed; use actix_server_config::{Io, IoStream, ServerConfig as SrvConfig}; use actix_service::{IntoNewService, NewService, Service}; -use actix_utils::cloneable::CloneableService; use futures::future::{ok, FutureResult}; use futures::{try_ready, Async, Future, IntoFuture, Poll, Stream}; use crate::body::MessageBody; +use crate::cloneable::CloneableService; use crate::config::{KeepAlive, ServiceConfig}; use crate::error::{DispatchError, Error, ParseError}; use crate::helpers::DataFactory; @@ -259,7 +259,7 @@ where H1ServiceHandler { srv: CloneableService::new(srv), expect: CloneableService::new(expect), - upgrade: upgrade.map(|s| CloneableService::new(s)), + upgrade: upgrade.map(CloneableService::new), cfg, on_connect, _t: PhantomData, diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 48d32993d..2bd7940dd 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -6,7 +6,6 @@ use std::{fmt, mem, net}; use actix_codec::{AsyncRead, AsyncWrite}; use actix_server_config::IoStream; use actix_service::Service; -use actix_utils::cloneable::CloneableService; use bitflags::bitflags; use bytes::{Bytes, BytesMut}; use futures::{try_ready, Async, Future, Poll, Sink, Stream}; @@ -20,6 +19,7 @@ use log::{debug, error, trace}; use tokio_timer::Delay; use crate::body::{Body, BodySize, MessageBody, ResponseBody}; +use crate::cloneable::CloneableService; use crate::config::ServiceConfig; use crate::error::{DispatchError, Error, ParseError, PayloadError, ResponseError}; use crate::helpers::DataFactory; diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index efc400da1..487d5b6ab 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -5,7 +5,6 @@ use std::{io, net, rc}; use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_server_config::{Io, IoStream, ServerConfig as SrvConfig}; use actix_service::{IntoNewService, NewService, Service}; -use actix_utils::cloneable::CloneableService; use bytes::Bytes; use futures::future::{ok, FutureResult}; use futures::{try_ready, Async, Future, IntoFuture, Poll, Stream}; @@ -14,6 +13,7 @@ use h2::RecvStream; use log::error; use crate::body::MessageBody; +use crate::cloneable::CloneableService; use crate::config::{KeepAlive, ServiceConfig}; use crate::error::{DispatchError, Error, ParseError, ResponseError}; use crate::helpers::DataFactory; @@ -256,7 +256,7 @@ where on_connect.take(), config.take().unwrap(), None, - peer_addr.clone(), + *peer_addr, )); self.poll() } diff --git a/actix-http/src/header/common/content_disposition.rs b/actix-http/src/header/common/content_disposition.rs index badf307a0..14fcc3517 100644 --- a/actix-http/src/header/common/content_disposition.rs +++ b/actix-http/src/header/common/content_disposition.rs @@ -70,6 +70,7 @@ impl<'a> From<&'a str> for DispositionType { /// assert_eq!(param.as_filename().unwrap(), "sample.txt"); /// ``` #[derive(Clone, Debug, PartialEq)] +#[allow(clippy::large_enum_variant)] pub enum DispositionParam { /// For [`DispositionType::FormData`] (i.e. *multipart/form-data*), the name of an field from /// the form. @@ -719,8 +720,10 @@ mod tests { }; assert_eq!(a, b); - let a = - HeaderValue::from_str("form-data; name=upload; filename=\"余固知謇謇之為患兮,忍而不能舍也.pptx\"").unwrap(); + let a = HeaderValue::from_str( + "form-data; name=upload; filename=\"余固知謇謇之為患兮,忍而不能舍也.pptx\"", + ) + .unwrap(); let a: ContentDisposition = ContentDisposition::from_raw(&a).unwrap(); let b = ContentDisposition { disposition: DispositionType::FormData, diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index ac085eaea..6b8874b23 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -1,8 +1,10 @@ //! Basic http primitives for actix-net framework. #![allow( clippy::type_complexity, + clippy::too_many_arguments, clippy::new_without_default, - clippy::borrow_interior_mutable_const + clippy::borrow_interior_mutable_const, + clippy::write_with_newline )] #[macro_use] @@ -11,6 +13,7 @@ extern crate log; pub mod body; mod builder; pub mod client; +mod cloneable; mod config; pub mod encoding; mod extensions; diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs index f3c01a12b..cf23a401c 100644 --- a/actix-http/src/message.rs +++ b/actix-http/src/message.rs @@ -385,6 +385,7 @@ impl Drop for BoxedResponseHead { pub struct MessagePool(RefCell>>); #[doc(hidden)] +#[allow(clippy::vec_box)] /// Request's objects pool pub struct BoxedResponsePool(RefCell>>); diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index 1ac018803..d37d377e5 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -6,13 +6,13 @@ use actix_server_config::{ Io as ServerIo, IoStream, Protocol, ServerConfig as SrvConfig, }; use actix_service::{IntoNewService, NewService, Service}; -use actix_utils::cloneable::CloneableService; use bytes::{Buf, BufMut, Bytes, BytesMut}; use futures::{try_ready, Async, Future, IntoFuture, Poll}; use h2::server::{self, Handshake}; use crate::body::MessageBody; use crate::builder::HttpServiceBuilder; +use crate::cloneable::CloneableService; use crate::config::{KeepAlive, ServiceConfig}; use crate::error::{DispatchError, Error}; use crate::helpers::DataFactory; @@ -285,7 +285,7 @@ where on_connect, srv: CloneableService::new(srv), expect: CloneableService::new(expect), - upgrade: upgrade.map(|s| CloneableService::new(s)), + upgrade: upgrade.map(CloneableService::new), _t: PhantomData, } } diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index eef874741..9b51b9229 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -47,10 +47,7 @@ impl Into for OpCode { Ping => 9, Pong => 10, Bad => { - debug_assert!( - false, - "Attempted to convert invalid opcode to u8. This is a bug." - ); + log::error!("Attempted to convert invalid opcode to u8. This is a bug."); 8 // if this somehow happens, a close frame will help us tear down quickly } } diff --git a/src/info.rs b/src/info.rs index a6a7d7282..0caa96832 100644 --- a/src/info.rs +++ b/src/info.rs @@ -25,7 +25,11 @@ impl ConnectionInfo { Ref::map(req.extensions(), |e| e.get().unwrap()) } - #[allow(clippy::cyclomatic_complexity, clippy::cognitive_complexity, clippy::borrow_interior_mutable_const)] + #[allow( + clippy::cyclomatic_complexity, + clippy::cognitive_complexity, + clippy::borrow_interior_mutable_const + )] fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo { let mut host = None; let mut scheme = None;