From 60b7aebd0a6de57cc480e8fdc9a755743654bde1 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 12 Sep 2019 21:52:46 +0600 Subject: [PATCH] fmt & clippy --- actix-http/Cargo.toml | 2 +- actix-http/src/client/error.rs | 2 +- actix-http/src/client/h1proto.rs | 28 +++++++++++++--------------- actix-http/src/client/h2proto.rs | 20 +++++++++++++------- actix-http/src/client/mod.rs | 2 +- actix-http/src/client/pool.rs | 2 +- actix-http/src/h1/client.rs | 10 +++++++--- actix-http/src/h1/encoder.rs | 23 +++++++++++++++-------- actix-multipart/src/server.rs | 28 ++++++++++++++++------------ awc/src/connect.rs | 21 +++++++++++++++------ awc/src/error.rs | 4 +++- awc/src/sender.rs | 4 ++-- awc/src/ws.rs | 5 ++++- src/app_service.rs | 2 +- src/middleware/mod.rs | 4 ++-- 15 files changed, 95 insertions(+), 62 deletions(-) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 3019b2897..cc7c885e7 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -66,7 +66,7 @@ hashbrown = "0.5.0" h2 = "0.1.16" http = "0.1.17" httparse = "1.3" -indexmap = "1.0" +indexmap = "1.2" lazy_static = "1.0" language-tags = "0.2" log = "0.4" diff --git a/actix-http/src/client/error.rs b/actix-http/src/client/error.rs index 40aef2cce..0ac5f30f5 100644 --- a/actix-http/src/client/error.rs +++ b/actix-http/src/client/error.rs @@ -147,4 +147,4 @@ impl From for SendRequestError { FreezeRequestError::Http(e) => e.into(), } } -} \ No newline at end of file +} diff --git a/actix-http/src/client/h1proto.rs b/actix-http/src/client/h1proto.rs index fa920ab92..b078c6a67 100644 --- a/actix-http/src/client/h1proto.rs +++ b/actix-http/src/client/h1proto.rs @@ -8,10 +8,10 @@ use futures::{Async, Future, Poll, Sink, Stream}; use crate::error::PayloadError; use crate::h1; +use crate::header::HeaderMap; use crate::http::header::{IntoHeaderValue, HOST}; use crate::message::{RequestHeadType, ResponseHead}; use crate::payload::{Payload, PayloadStream}; -use crate::header::HeaderMap; use super::connection::{ConnectionLifetime, ConnectionType, IoConnection}; use super::error::{ConnectError, SendRequestError}; @@ -30,7 +30,9 @@ where B: MessageBody, { // set request host header - if !head.as_ref().headers.contains_key(HOST) && !head.extra_headers().iter().any(|h| h.contains_key(HOST)) { + if !head.as_ref().headers.contains_key(HOST) + && !head.extra_headers().iter().any(|h| h.contains_key(HOST)) + { if let Some(host) = head.as_ref().uri.host() { let mut wrt = BytesMut::with_capacity(host.len() + 5).writer(); @@ -40,20 +42,16 @@ where }; match wrt.get_mut().take().freeze().try_into() { - Ok(value) => { - match head { - RequestHeadType::Owned(ref mut head) => { - head.headers.insert(HOST, value) - }, - RequestHeadType::Rc(_, ref mut extra_headers) => { - let headers = extra_headers.get_or_insert(HeaderMap::new()); - headers.insert(HOST, value) - }, + Ok(value) => match head { + RequestHeadType::Owned(ref mut head) => { + head.headers.insert(HOST, value) } - } - Err(e) => { - log::error!("Can not set HOST header {}", e) - } + RequestHeadType::Rc(_, ref mut extra_headers) => { + let headers = extra_headers.get_or_insert(HeaderMap::new()); + headers.insert(HOST, value) + } + }, + Err(e) => log::error!("Can not set HOST header {}", e), } } } diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index 2993d89d8..5744a1547 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -9,9 +9,9 @@ use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING}; use http::{request::Request, HttpTryFrom, Method, Version}; use crate::body::{BodySize, MessageBody}; +use crate::header::HeaderMap; use crate::message::{RequestHeadType, ResponseHead}; use crate::payload::Payload; -use crate::header::HeaderMap; use super::connection::{ConnectionType, IoConnection}; use super::error::SendRequestError; @@ -69,15 +69,21 @@ where // Extracting extra headers from RequestHeadType. HeaderMap::new() does not allocate. let (head, extra_headers) = match head { - RequestHeadType::Owned(head) => (RequestHeadType::Owned(head), HeaderMap::new()), - RequestHeadType::Rc(head, extra_headers) => (RequestHeadType::Rc(head, None), extra_headers.unwrap_or(HeaderMap::new())), + RequestHeadType::Owned(head) => { + (RequestHeadType::Owned(head), HeaderMap::new()) + } + RequestHeadType::Rc(head, extra_headers) => ( + RequestHeadType::Rc(head, None), + extra_headers.unwrap_or_else(HeaderMap::new), + ), }; // merging headers from head and extra headers. - let headers = head.as_ref().headers.iter() - .filter(|(name, _)| { - !extra_headers.contains_key(*name) - }) + let headers = head + .as_ref() + .headers + .iter() + .filter(|(name, _)| !extra_headers.contains_key(*name)) .chain(extra_headers.iter()); // copy headers diff --git a/actix-http/src/client/mod.rs b/actix-http/src/client/mod.rs index 04427ce42..a45aebcd5 100644 --- a/actix-http/src/client/mod.rs +++ b/actix-http/src/client/mod.rs @@ -10,7 +10,7 @@ mod pool; pub use self::connection::Connection; pub use self::connector::Connector; -pub use self::error::{ConnectError, InvalidUrl, SendRequestError, FreezeRequestError}; +pub use self::error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError}; pub use self::pool::Protocol; #[derive(Clone)] diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 24a187392..a3522ff8a 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -326,7 +326,7 @@ impl Inner { fn release_waiter(&mut self, key: &Key, token: usize) { self.waiters.remove(token); - self.waiters_queue.remove(&(key.clone(), token)); + let _ = self.waiters_queue.shift_remove(&(key.clone(), token)); } } diff --git a/actix-http/src/h1/client.rs b/actix-http/src/h1/client.rs index c0bbcc694..bea629c4f 100644 --- a/actix-http/src/h1/client.rs +++ b/actix-http/src/h1/client.rs @@ -16,9 +16,11 @@ use super::{Message, MessageType}; use crate::body::BodySize; use crate::config::ServiceConfig; use crate::error::{ParseError, PayloadError}; -use crate::helpers; -use crate::message::{ConnectionType, Head, MessagePool, RequestHead, RequestHeadType, ResponseHead}; use crate::header::HeaderMap; +use crate::helpers; +use crate::message::{ + ConnectionType, Head, MessagePool, RequestHead, RequestHeadType, ResponseHead, +}; bitflags! { struct Flags: u8 { @@ -197,7 +199,9 @@ impl Encoder for ClientCodec { Message::Item((mut head, length)) => { let inner = &mut self.inner; inner.version = head.as_ref().version; - inner.flags.set(Flags::HEAD, head.as_ref().method == Method::HEAD); + inner + .flags + .set(Flags::HEAD, head.as_ref().method == Method::HEAD); // connection status inner.ctype = match head.as_ref().connection_type() { diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index 380dfe328..51ea497e0 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -2,9 +2,9 @@ use std::fmt::Write as FmtWrite; use std::io::Write; use std::marker::PhantomData; +use std::rc::Rc; use std::str::FromStr; use std::{cmp, fmt, io, mem}; -use std::rc::Rc; use bytes::{BufMut, Bytes, BytesMut}; @@ -16,7 +16,7 @@ use crate::http::header::{ HeaderValue, ACCEPT_ENCODING, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, }; use crate::http::{HeaderMap, Method, StatusCode, Version}; -use crate::message::{ConnectionType, Head, RequestHead, ResponseHead, RequestHeadType}; +use crate::message::{ConnectionType, Head, RequestHead, RequestHeadType, ResponseHead}; use crate::request::Request; use crate::response::Response; @@ -134,10 +134,11 @@ pub(crate) trait MessageType: Sized { // merging headers from head and extra headers. HeaderMap::new() does not allocate. let empty_headers = HeaderMap::new(); let extra_headers = self.extra_headers().unwrap_or(&empty_headers); - let headers = self.headers().inner.iter() - .filter(|(name, _)| { - !extra_headers.contains_key(*name) - }) + let headers = self + .headers() + .inner + .iter() + .filter(|(name, _)| !extra_headers.contains_key(*name)) .chain(extra_headers.inner.iter()); // write headers @@ -604,10 +605,16 @@ mod tests { let mut bytes = BytesMut::with_capacity(2048); let mut head = RequestHead::default(); - head.headers.insert(AUTHORIZATION, HeaderValue::from_static("some authorization")); + head.headers.insert( + AUTHORIZATION, + HeaderValue::from_static("some authorization"), + ); let mut extra_headers = HeaderMap::new(); - extra_headers.insert(AUTHORIZATION,HeaderValue::from_static("another authorization")); + extra_headers.insert( + AUTHORIZATION, + HeaderValue::from_static("another authorization"), + ); extra_headers.insert(DATE, HeaderValue::from_static("date")); let mut head = RequestHeadType::Rc(Rc::new(head), Some(extra_headers)); diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index 3312a580a..a7c787f46 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -178,13 +178,15 @@ impl InnerMultipart { Some(chunk) => { if chunk.len() < boundary.len() + 4 || &chunk[..2] != b"--" - || &chunk[2..boundary.len() + 2] != boundary.as_bytes() { + || &chunk[2..boundary.len() + 2] != boundary.as_bytes() + { Err(MultipartError::Boundary) } else if &chunk[boundary.len() + 2..] == b"\r\n" { Ok(Some(false)) } else if &chunk[boundary.len() + 2..boundary.len() + 4] == b"--" && (chunk.len() == boundary.len() + 4 - || &chunk[boundary.len() + 4..] == b"\r\n") { + || &chunk[boundary.len() + 4..] == b"\r\n") + { Ok(Some(true)) } else { Err(MultipartError::Boundary) @@ -781,8 +783,10 @@ impl PayloadBuffer { /// Read bytes until new line delimiter or eof pub fn readline_or_eof(&mut self) -> Result, MultipartError> { match self.readline() { - Err(MultipartError::Incomplete) if self.eof => Ok(Some(self.buf.take().freeze())), - line => line + Err(MultipartError::Incomplete) if self.eof => { + Ok(Some(self.buf.take().freeze())) + } + line => line, } } @@ -859,14 +863,14 @@ mod tests { fn create_simple_request_with_header() -> (Bytes, HeaderMap) { let bytes = Bytes::from( "testasdadsad\r\n\ - --abbc761f78ff4d7cb7573b5a23f96ef0\r\n\ - Content-Disposition: form-data; name=\"file\"; filename=\"fn.txt\"\r\n\ - Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\ - test\r\n\ - --abbc761f78ff4d7cb7573b5a23f96ef0\r\n\ - Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\ - data\r\n\ - --abbc761f78ff4d7cb7573b5a23f96ef0--\r\n" + --abbc761f78ff4d7cb7573b5a23f96ef0\r\n\ + Content-Disposition: form-data; name=\"file\"; filename=\"fn.txt\"\r\n\ + Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\ + test\r\n\ + --abbc761f78ff4d7cb7573b5a23f96ef0\r\n\ + Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\ + data\r\n\ + --abbc761f78ff4d7cb7573b5a23f96ef0--\r\n", ); let mut headers = HeaderMap::new(); headers.insert( diff --git a/awc/src/connect.rs b/awc/src/connect.rs index 82fd6a759..97864d300 100644 --- a/awc/src/connect.rs +++ b/awc/src/connect.rs @@ -1,5 +1,5 @@ -use std::{fmt, io, net}; use std::rc::Rc; +use std::{fmt, io, net}; use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_http::body::Body; @@ -7,8 +7,8 @@ use actix_http::client::{ Connect as ClientConnect, ConnectError, Connection, SendRequestError, }; use actix_http::h1::ClientCodec; -use actix_http::{RequestHead, RequestHeadType, ResponseHead}; use actix_http::http::HeaderMap; +use actix_http::{RequestHead, RequestHeadType, ResponseHead}; use actix_service::Service; use futures::{Future, Poll}; @@ -82,7 +82,9 @@ where }) .from_err() // send request - .and_then(move |connection| connection.send_request(RequestHeadType::from(head), body)) + .and_then(move |connection| { + connection.send_request(RequestHeadType::from(head), body) + }) .map(|(head, payload)| ClientResponse::new(head, payload)), ) } @@ -103,7 +105,10 @@ where }) .from_err() // send request - .and_then(move |connection| connection.send_request(RequestHeadType::Rc(head, extra_headers), body)) + .and_then(move |connection| { + connection + .send_request(RequestHeadType::Rc(head, extra_headers), body) + }) .map(|(head, payload)| ClientResponse::new(head, payload)), ) } @@ -127,7 +132,9 @@ where }) .from_err() // send request - .and_then(move |connection| connection.open_tunnel(RequestHeadType::from(head))) + .and_then(move |connection| { + connection.open_tunnel(RequestHeadType::from(head)) + }) .map(|(head, framed)| { let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io)))); (head, framed) @@ -155,7 +162,9 @@ where }) .from_err() // send request - .and_then(move |connection| connection.open_tunnel(RequestHeadType::Rc(head, extra_headers))) + .and_then(move |connection| { + connection.open_tunnel(RequestHeadType::Rc(head, extra_headers)) + }) .map(|(head, framed)| { let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io)))); (head, framed) diff --git a/awc/src/error.rs b/awc/src/error.rs index 4eb929007..eb8d03e2b 100644 --- a/awc/src/error.rs +++ b/awc/src/error.rs @@ -1,5 +1,7 @@ //! Http client errors -pub use actix_http::client::{ConnectError, InvalidUrl, SendRequestError, FreezeRequestError}; +pub use actix_http::client::{ + ConnectError, FreezeRequestError, InvalidUrl, SendRequestError, +}; pub use actix_http::error::PayloadError; pub use actix_http::ws::HandshakeError as WsHandshakeError; pub use actix_http::ws::ProtocolError as WsProtocolError; diff --git a/awc/src/sender.rs b/awc/src/sender.rs index c8e169cb1..95109b92d 100644 --- a/awc/src/sender.rs +++ b/awc/src/sender.rs @@ -90,7 +90,7 @@ impl Future for SendClientRequest { Ok(Async::Ready(res)) } SendClientRequest::Err(ref mut e) => match e.take() { - Some(e) => Err(e.into()), + Some(e) => Err(e), None => panic!("Attempting to call completed future"), }, } @@ -153,7 +153,7 @@ impl RequestSender { SendClientRequest::new( fut, response_decompress, - timeout.or_else(|| config.timeout.clone()), + timeout.or_else(|| config.timeout), ) } diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 67be9e9d8..77cbc7ca4 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -234,7 +234,10 @@ impl WebsocketsRequest { } if !self.head.headers.contains_key(header::HOST) { - self.head.headers.insert(header::HOST, HeaderValue::from_str(uri.host().unwrap()).unwrap()); + self.head.headers.insert( + header::HOST, + HeaderValue::from_str(uri.host().unwrap()).unwrap(), + ); } // set cookies diff --git a/src/app_service.rs b/src/app_service.rs index 736c35010..513b4aa4b 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -169,7 +169,7 @@ where match self.data_factories_fut[idx].poll()? { Async::Ready(f) => { self.data_factories.push(f); - self.data_factories_fut.remove(idx); + let _ = self.data_factories_fut.remove(idx); } Async::NotReady => idx += 1, } diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 311d0ee99..84e0758bf 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -2,13 +2,13 @@ mod compress; pub use self::compress::{BodyEncoding, Compress}; +mod condition; mod defaultheaders; pub mod errhandlers; mod logger; mod normalize; -mod condition; +pub use self::condition::Condition; pub use self::defaultheaders::DefaultHeaders; pub use self::logger::Logger; pub use self::normalize::NormalizePath; -pub use self::condition::Condition;