diff --git a/actix-http/src/client/connector.rs b/actix-http/src/client/connector.rs index 701212ab7..c04b42eac 100644 --- a/actix-http/src/client/connector.rs +++ b/actix-http/src/client/connector.rs @@ -19,14 +19,10 @@ use super::Connect; #[cfg(feature = "ssl")] use openssl::ssl::SslConnector; -#[cfg(all(not(feature = "ssl"), feature = "rust-tls"))] -use rustls::{Session, ClientConfig}; -#[cfg(all(not(feature = "ssl"), feature = "rust-tls"))] -use std::sync::Arc; -#[cfg(all(not(feature = "ssl"), feature = "rust-tls"))] +#[cfg(feature = "rust-tls")] type SslConnector = Arc; -#[cfg(all(not(feature = "ssl"), not(feature = "rust-tls")))] +#[cfg(not(any(feature = "ssl", feature = "rust-tls")))] type SslConnector = (); /// Manages http client network connectivity @@ -74,15 +70,18 @@ impl Connector<(), ()> { .map_err(|e| error!("Can not set alpn protocol: {:?}", e)); ssl.build() } - #[cfg(all(not(feature = "ssl"), feature = "rust-tls"))] + #[cfg(feature = "rust-tls")] { + use rustls::{Session, ClientConfig}; + use std::sync::Arc; + let protos = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; let mut config = ClientConfig::new(); config.set_protocols(&protos); config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); Arc::new(config) } - #[cfg(all(not(feature = "ssl"), not(feature = "rust-tls")))] + #[cfg(not(any(feature = "ssl", feature = "rust-tls")))] {} }; @@ -140,7 +139,7 @@ where self } - #[cfg(feature = "ssl")] + #[cfg(any(feature = "ssl", feature = "rust-tls"))] /// Use custom `SslConnector` instance. pub fn ssl(mut self, connector: SslConnector) -> Self { self.ssl = connector; @@ -197,7 +196,7 @@ where self, ) -> impl Service + Clone { - #[cfg(all(not(feature = "ssl"), not(feature = "rust-tls")))] + #[cfg(not(any(feature = "ssl", feature = "rust-tls")))] { let connector = TimeoutService::new( self.timeout, @@ -287,7 +286,7 @@ where ), } } - #[cfg(all(not(feature = "ssl"), feature = "rust-tls"))] + #[cfg(feature = "rust-tls")] { const H2: &[u8] = b"h2"; use actix_connect::ssl::RustlsConnector; @@ -355,7 +354,7 @@ where } } -#[cfg(all(not(feature = "ssl"), not(feature = "rust-tls")))] +#[cfg(not(any(feature = "ssl", feature = "rust-tls")))] mod connect_impl { use futures::future::{err, Either, FutureResult}; use futures::Poll; @@ -417,150 +416,7 @@ mod connect_impl { } } -#[cfg(feature = "ssl")] -mod connect_impl { - use std::marker::PhantomData; - - use futures::future::{Either, FutureResult}; - use futures::{Async, Future, Poll}; - - use super::*; - use crate::client::connection::EitherConnection; - - pub(crate) struct InnerConnector - where - Io1: AsyncRead + AsyncWrite + 'static, - Io2: AsyncRead + AsyncWrite + 'static, - T1: Service, - T2: Service, - { - pub(crate) tcp_pool: ConnectionPool, - pub(crate) ssl_pool: ConnectionPool, - } - - impl Clone for InnerConnector - where - Io1: AsyncRead + AsyncWrite + 'static, - Io2: AsyncRead + AsyncWrite + 'static, - T1: Service - + Clone - + 'static, - T2: Service - + Clone - + 'static, - { - fn clone(&self) -> Self { - InnerConnector { - tcp_pool: self.tcp_pool.clone(), - ssl_pool: self.ssl_pool.clone(), - } - } - } - - impl Service for InnerConnector - where - Io1: AsyncRead + AsyncWrite + 'static, - Io2: AsyncRead + AsyncWrite + 'static, - T1: Service - + Clone - + 'static, - T2: Service - + Clone - + 'static, - { - type Request = Connect; - type Response = EitherConnection; - type Error = ConnectError; - type Future = Either< - FutureResult, - Either< - InnerConnectorResponseA, - InnerConnectorResponseB, - >, - >; - - fn poll_ready(&mut self) -> Poll<(), Self::Error> { - self.tcp_pool.poll_ready() - } - - fn call(&mut self, req: Connect) -> Self::Future { - match req.uri.scheme_str() { - Some("https") | Some("wss") => { - Either::B(Either::B(InnerConnectorResponseB { - fut: self.ssl_pool.call(req), - _t: PhantomData, - })) - } - _ => Either::B(Either::A(InnerConnectorResponseA { - fut: self.tcp_pool.call(req), - _t: PhantomData, - })), - } - } - } - - pub(crate) struct InnerConnectorResponseA - where - Io1: AsyncRead + AsyncWrite + 'static, - T: Service - + Clone - + 'static, - { - fut: as Service>::Future, - _t: PhantomData, - } - - impl Future for InnerConnectorResponseA - where - T: Service - + Clone - + 'static, - Io1: AsyncRead + AsyncWrite + 'static, - Io2: AsyncRead + AsyncWrite + 'static, - { - type Item = EitherConnection; - type Error = ConnectError; - - fn poll(&mut self) -> Poll { - match self.fut.poll()? { - Async::NotReady => Ok(Async::NotReady), - Async::Ready(res) => Ok(Async::Ready(EitherConnection::A(res))), - } - } - } - - pub(crate) struct InnerConnectorResponseB - where - Io2: AsyncRead + AsyncWrite + 'static, - T: Service - + Clone - + 'static, - { - fut: as Service>::Future, - _t: PhantomData, - } - - impl Future for InnerConnectorResponseB - where - T: Service - + Clone - + 'static, - Io1: AsyncRead + AsyncWrite + 'static, - Io2: AsyncRead + AsyncWrite + 'static, - { - type Item = EitherConnection; - type Error = ConnectError; - - fn poll(&mut self) -> Poll { - match self.fut.poll()? { - Async::NotReady => Ok(Async::NotReady), - Async::Ready(res) => Ok(Async::Ready(EitherConnection::B(res))), - } - } - } -} - -#[cfg(all(not(feature = "ssl"), feature = "rust-tls"))] +#[cfg(any(feature = "ssl", feature = "rust-tls"))] mod connect_impl { use std::marker::PhantomData;