From f1b3b532b7eca4bb7a7a87bf3ff2fb71f182664c Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 27 Jun 2022 03:04:57 +0100 Subject: [PATCH] document new items --- actix-http/src/lib.rs | 1 + actix-http/src/service.rs | 19 +++++++++++-------- actix-web/src/server.rs | 24 +++++++++++++++--------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index 2544d6012..184049860 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -25,6 +25,7 @@ )] #![doc(html_logo_url = "https://actix.rs/img/logo.png")] #![doc(html_favicon_url = "https://actix.rs/favicon.ico")] +#![cfg_attr(docsrs, feature(doc_cfg))] pub use ::http::{uri, uri::Uri}; pub use ::http::{Method, StatusCode, Version}; diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index e3de9d23b..469a95ba0 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -181,17 +181,17 @@ where } } +/// Configuration options used when accepting TLS connection. #[cfg(any(feature = "openssl", feature = "rustls"))] +#[cfg_attr(docsrs, doc(cfg(any(feature = "openssl", feature = "rustls"))))] +#[derive(Debug, Default)] pub struct TlsAcceptorConfig { pub(crate) handshake_timeout: Option, } #[cfg(any(feature = "openssl", feature = "rustls"))] impl TlsAcceptorConfig { - pub fn new(handshake_timeout: Option) -> Self { - Self { handshake_timeout } - } - + /// Set TLS handshake timeout duration. pub fn handshake_timeout(self, dur: std::time::Duration) -> Self { Self { handshake_timeout: Some(dur), @@ -249,10 +249,10 @@ mod openssl { Error = TlsError, InitError = (), > { - self.openssl_with_config(acceptor, TlsAcceptorConfig::new(None)) + self.openssl_with_config(acceptor, TlsAcceptorConfig::default()) } - /// Create OpenSSL based service with configuration. + /// Create OpenSSL based service with custom TLS acceptor configuration. pub fn openssl_with_config( self, acceptor: SslAcceptor, @@ -265,6 +265,7 @@ mod openssl { InitError = (), > { let mut acceptor = Acceptor::new(acceptor); + if let Some(handshake_timeout) = tls_acceptor_config.handshake_timeout { acceptor.set_handshake_timeout(handshake_timeout); } @@ -341,10 +342,10 @@ mod rustls { Error = TlsError, InitError = (), > { - self.rustls_with_config(config, TlsAcceptorConfig::new(None)) + self.rustls_with_config(config, TlsAcceptorConfig::default()) } - /// Create Rustls based service with configuration. + /// Create Rustls based service with custom TLS acceptor configuration. pub fn rustls_with_config( self, mut config: ServerConfig, @@ -361,9 +362,11 @@ mod rustls { config.alpn_protocols = protos; let mut acceptor = Acceptor::new(config); + if let Some(handshake_timeout) = tls_acceptor_config.handshake_timeout { acceptor.set_handshake_timeout(handshake_timeout); } + acceptor .map_init_err(|_| { unreachable!("TLS acceptor service factory does not error on init") diff --git a/actix-web/src/server.rs b/actix-web/src/server.rs index 47b243352..169eafab0 100644 --- a/actix-web/src/server.rs +++ b/actix-web/src/server.rs @@ -232,19 +232,21 @@ where self } - #[cfg(any(feature = "openssl", feature = "rustls"))] /// Set TLS handshake timeout. /// /// Defines a timeout for TLS handshake. If the TLS handshake does not complete /// within this time, the connection is closed. /// /// By default handshake timeout is set to 3000 milliseconds. + #[cfg(any(feature = "openssl", feature = "rustls"))] + #[cfg_attr(docsrs, doc(cfg(any(feature = "openssl", feature = "rustls"))))] pub fn tls_handshake_timeout(self, dur: Duration) -> Self { self.config .lock() .unwrap() .tls_handshake_timeout .replace(dur); + self } @@ -399,13 +401,15 @@ where .into_factory() .map_err(|err| err.into().error_response()); + let acceptor_config = match c.tls_handshake_timeout { + Some(dur) => TlsAcceptorConfig::default().handshake_timeout(dur), + None => TlsAcceptorConfig::default(), + }; + svc.finish(map_config(fac, move |_| { AppConfig::new(true, host.clone(), addr) })) - .openssl_with_config( - acceptor.clone(), - TlsAcceptorConfig::new(c.tls_handshake_timeout), - ) + .openssl_with_config(acceptor.clone(), acceptor_config) })?; Ok(self) @@ -460,13 +464,15 @@ where .into_factory() .map_err(|err| err.into().error_response()); + let acceptor_config = match c.tls_handshake_timeout { + Some(dur) => TlsAcceptorConfig::default().handshake_timeout(dur), + None => TlsAcceptorConfig::default(), + }; + svc.finish(map_config(fac, move |_| { AppConfig::new(true, host.clone(), addr) })) - .rustls_with_config( - config.clone(), - TlsAcceptorConfig::new(c.tls_handshake_timeout), - ) + .rustls_with_config(config.clone(), acceptor_config) })?; Ok(self)