diff --git a/src/client/connector.rs b/src/client/connector.rs index 51246dc6c..239a00c5e 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -19,36 +19,28 @@ use tokio_timer::Delay; #[cfg(feature = "alpn")] use { openssl::ssl::{Error as SslError, SslConnector, SslMethod}, - tokio_openssl::SslConnectorExt + tokio_openssl::SslConnectorExt, }; #[cfg(all(feature = "tls", not(feature = "alpn")))] use { native_tls::{Error as SslError, TlsConnector as NativeTlsConnector}, - tokio_tls::TlsConnector as SslConnector + tokio_tls::TlsConnector as SslConnector, }; -#[cfg( - all( - feature = "rust-tls", - not(any(feature = "alpn", feature = "tls")) - ) -)] +#[cfg(all( + feature = "rust-tls", + not(any(feature = "alpn", feature = "tls")) +))] use { - rustls::ClientConfig, - std::io::Error as SslError, - std::sync::Arc, - tokio_rustls::ClientConfigExt, - webpki::DNSNameRef, - webpki_roots, + rustls::ClientConfig, std::io::Error as SslError, std::sync::Arc, + tokio_rustls::ClientConfigExt, webpki::DNSNameRef, webpki_roots, }; -#[cfg( - all( - feature = "rust-tls", - not(any(feature = "alpn", feature = "tls")) - ) -)] +#[cfg(all( + feature = "rust-tls", + not(any(feature = "alpn", feature = "tls")) +))] type SslConnector = Arc; #[cfg(not(any(feature = "alpn", feature = "tls", feature = "rust-tls")))] @@ -255,17 +247,19 @@ impl Default for ClientConnector { fn default() -> ClientConnector { let connector = { #[cfg(all(feature = "alpn"))] - { SslConnector::builder(SslMethod::tls()).unwrap().build() } + { + SslConnector::builder(SslMethod::tls()).unwrap().build() + } #[cfg(all(feature = "tls", not(feature = "alpn")))] - { NativeTlsConnector::builder().build().unwrap().into() } + { + NativeTlsConnector::builder().build().unwrap().into() + } - #[cfg( - all( - feature = "rust-tls", - not(any(feature = "alpn", feature = "tls")) - ) - )] + #[cfg(all( + feature = "rust-tls", + not(any(feature = "alpn", feature = "tls")) + ))] { let mut config = ClientConfig::new(); config @@ -275,7 +269,9 @@ impl Default for ClientConnector { } #[cfg(not(any(feature = "alpn", feature = "tls", feature = "rust-tls")))] - { () } + { + () + } }; ClientConnector::with_connector_impl(connector) @@ -326,12 +322,10 @@ impl ClientConnector { Self::with_connector_impl(connector) } - #[cfg( - all( - feature = "rust-tls", - not(any(feature = "alpn", feature = "tls")) - ) - )] + #[cfg(all( + feature = "rust-tls", + not(any(feature = "alpn", feature = "tls")) + ))] /// Create `ClientConnector` actor with custom `SslConnector` instance. /// /// By default `ClientConnector` uses very a simple SSL configuration. @@ -379,12 +373,10 @@ impl ClientConnector { Self::with_connector_impl(Arc::new(connector)) } - #[cfg( - all( - feature = "tls", - not(any(feature = "alpn", feature = "rust-tls")) - ) - )] + #[cfg(all( + feature = "tls", + not(any(feature = "alpn", feature = "rust-tls")) + ))] /// Create `ClientConnector` actor with custom `SslConnector` instance. /// /// By default `ClientConnector` uses very a simple SSL configuration. @@ -805,12 +797,10 @@ impl ClientConnector { } } - #[cfg( - all( - feature = "rust-tls", - not(any(feature = "alpn", feature = "tls")) - ) - )] + #[cfg(all( + feature = "rust-tls", + not(any(feature = "alpn", feature = "tls")) + ))] match res { Err(err) => { let _ = waiter.tx.send(Err(err.into())); @@ -1296,7 +1286,7 @@ impl AsyncWrite for Connection { } #[cfg(feature = "tls")] -use tokio_tls::{TlsStream}; +use tokio_tls::TlsStream; #[cfg(feature = "tls")] /// This is temp solution untile actix-net migration diff --git a/src/client/parser.rs b/src/client/parser.rs index 5fd81da25..0ee4598de 100644 --- a/src/client/parser.rs +++ b/src/client/parser.rs @@ -50,7 +50,9 @@ impl HttpResponseParser { } Async::NotReady => { if buf.capacity() >= MAX_BUFFER_SIZE { - return Err(HttpResponseParserError::Error(ParseError::TooLarge)); + return Err(HttpResponseParserError::Error( + ParseError::TooLarge, + )); } // Parser needs more data. } @@ -63,9 +65,7 @@ impl HttpResponseParser { } Ok(Async::Ready(_)) => (), Ok(Async::NotReady) => return Ok(Async::NotReady), - Err(err) => { - return Err(HttpResponseParserError::Error(err.into())) - } + Err(err) => return Err(HttpResponseParserError::Error(err.into())), } } } diff --git a/src/param.rs b/src/param.rs index 063159d72..d0664df99 100644 --- a/src/param.rs +++ b/src/param.rs @@ -236,7 +236,6 @@ macro_rules! FROM_STR { ($type:ty) => { impl FromParam for $type { type Err = InternalError<<$type as FromStr>::Err>; - fn from_param(val: &str) -> Result { <$type as FromStr>::from_str(val) .map_err(|e| InternalError::new(e, StatusCode::BAD_REQUEST)) diff --git a/src/server/channel.rs b/src/server/channel.rs index 84f301513..bec1c4c87 100644 --- a/src/server/channel.rs +++ b/src/server/channel.rs @@ -160,8 +160,9 @@ where if let Some(HttpProtocol::Unknown(settings, addr, io, buf)) = self.proto.take() { match kind { ProtocolKind::Http1 => { - self.proto = - Some(HttpProtocol::H1(h1::Http1::new(settings, io, addr, buf, is_eof))); + self.proto = Some(HttpProtocol::H1(h1::Http1::new( + settings, io, addr, buf, is_eof, + ))); return self.poll(); } ProtocolKind::Http2 => { diff --git a/src/server/h1.rs b/src/server/h1.rs index 1acae26ec..dc88cac9f 100644 --- a/src/server/h1.rs +++ b/src/server/h1.rs @@ -94,7 +94,11 @@ where buf: BytesMut, is_eof: bool, ) -> Self { Http1 { - flags: if is_eof { Flags::READ_DISCONNECTED } else { Flags::KEEPALIVE }, + flags: if is_eof { + Flags::READ_DISCONNECTED + } else { + Flags::KEEPALIVE + }, stream: H1Writer::new(stream, Rc::clone(&settings)), decoder: H1Decoder::new(), payload: None, @@ -118,8 +122,11 @@ where #[inline] fn can_read(&self) -> bool { - if self.flags.intersects(Flags::ERROR | Flags::READ_DISCONNECTED) { - return false + if self + .flags + .intersects(Flags::ERROR | Flags::READ_DISCONNECTED) + { + return false; } if let Some(ref info) = self.payload { @@ -171,14 +178,15 @@ where // shutdown if self.flags.contains(Flags::SHUTDOWN) { if self.flags.intersects( - Flags::ERROR | Flags::READ_DISCONNECTED | Flags::WRITE_DISCONNECTED) { - return Ok(Async::Ready(())) + Flags::ERROR | Flags::READ_DISCONNECTED | Flags::WRITE_DISCONNECTED, + ) { + return Ok(Async::Ready(())); } match self.stream.poll_completed(true) { Ok(Async::NotReady) => return Ok(Async::NotReady), Ok(Async::Ready(_)) => return Ok(Async::Ready(())), Err(err) => { - debug!("Error sendips ng data: {}", err); + debug!("Error sending data: {}", err); return Err(()); } } @@ -240,7 +248,8 @@ where let mut idx = 0; while idx < self.tasks.len() { // only one task can do io operation in http/1 - if !io && !self.tasks[idx].flags.contains(EntryFlags::EOF) + if !io + && !self.tasks[idx].flags.contains(EntryFlags::EOF) && !self.flags.contains(Flags::WRITE_DISCONNECTED) { // io is corrupted, send buffer @@ -320,9 +329,7 @@ where // check stream state if self.flags.contains(Flags::STARTED) { match self.stream.poll_completed(false) { - Ok(Async::NotReady) => { - return Ok(Async::NotReady) - }, + Ok(Async::NotReady) => return Ok(Async::NotReady), Err(err) => { debug!("Error sending data: {}", err); self.notify_disconnect(); @@ -459,11 +466,13 @@ where } } Ok(None) => { - if self.flags.contains(Flags::READ_DISCONNECTED) && self.tasks.is_empty() { + if self.flags.contains(Flags::READ_DISCONNECTED) + && self.tasks.is_empty() + { self.client_disconnect(); } - break - }, + break; + } Err(e) => { self.flags.insert(Flags::ERROR); if let Some(mut payload) = self.payload.take() { @@ -618,24 +627,36 @@ mod tests { } #[test] - fn test_req_parse() { + fn test_req_parse1() { let buf = Buffer::new("GET /test HTTP/1.1\r\n\r\n"); let readbuf = BytesMut::new(); let settings = Rc::new(wrk_settings()); - let mut h1 = Http1::new(Rc::clone(&settings), buf, None, readbuf, true); + let mut h1 = Http1::new(Rc::clone(&settings), buf, None, readbuf, false); h1.poll_io(); h1.poll_io(); assert_eq!(h1.tasks.len(), 1); } + #[test] + fn test_req_parse2() { + let buf = Buffer::new(""); + let readbuf = + BytesMut::from(Vec::::from(&b"GET /test HTTP/1.1\r\n\r\n"[..])); + let settings = Rc::new(wrk_settings()); + + let mut h1 = Http1::new(Rc::clone(&settings), buf, None, readbuf, true); + h1.poll_io(); + assert_eq!(h1.tasks.len(), 1); + } + #[test] fn test_req_parse_err() { let buf = Buffer::new("GET /test HTTP/1\r\n\r\n"); let readbuf = BytesMut::new(); let settings = Rc::new(wrk_settings()); - let mut h1 = Http1::new(Rc::clone(&settings), buf, None, readbuf, true); + let mut h1 = Http1::new(Rc::clone(&settings), buf, None, readbuf, false); h1.poll_io(); h1.poll_io(); assert!(h1.flags.contains(Flags::ERROR));