mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-27 07:19:04 +02:00
Expose option for setting TLS handshake timeout (#2752)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
@ -1,12 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency.
|
||||
### Added
|
||||
- Add `ServiceRequest::{parts, request}()` getter methods. [#2786]
|
||||
- Add configuration options for TLS handshake timeout via `HttpServer::{rustls, openssl}_with_config` methods. [#2752]
|
||||
|
||||
### Changed
|
||||
- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency.
|
||||
|
||||
[#2752]: https://github.com/actix/actix-web/pull/2752
|
||||
[#2786]: https://github.com/actix/actix-web/pull/2786
|
||||
|
||||
|
||||
## 4.1.0 - 2022-06-11
|
||||
### Added
|
||||
- Add `ServiceRequest::extract()` to make it easier to use extractors when writing middlewares. [#2647]
|
||||
|
@ -18,6 +18,9 @@ use actix_tls::accept::openssl::reexports::{AlpnError, SslAcceptor, SslAcceptorB
|
||||
#[cfg(feature = "rustls")]
|
||||
use actix_tls::accept::rustls::reexports::ServerConfig as RustlsServerConfig;
|
||||
|
||||
#[cfg(any(feature = "openssl", feature = "rustls"))]
|
||||
use actix_http::TlsAcceptorConfig;
|
||||
|
||||
use crate::{config::AppConfig, Error};
|
||||
|
||||
struct Socket {
|
||||
@ -30,6 +33,8 @@ struct Config {
|
||||
keep_alive: KeepAlive,
|
||||
client_request_timeout: Duration,
|
||||
client_disconnect_timeout: Duration,
|
||||
#[cfg(any(feature = "openssl", feature = "rustls"))]
|
||||
tls_handshake_timeout: Option<Duration>,
|
||||
}
|
||||
|
||||
/// An HTTP Server.
|
||||
@ -92,6 +97,8 @@ where
|
||||
keep_alive: KeepAlive::default(),
|
||||
client_request_timeout: Duration::from_secs(5),
|
||||
client_disconnect_timeout: Duration::from_secs(1),
|
||||
#[cfg(any(feature = "rustls", feature = "openssl"))]
|
||||
tls_handshake_timeout: None,
|
||||
})),
|
||||
backlog: 1024,
|
||||
sockets: Vec::new(),
|
||||
@ -225,6 +232,24 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[deprecated(since = "4.0.0", note = "Renamed to `client_disconnect_timeout`.")]
|
||||
pub fn client_shutdown(self, dur: u64) -> Self {
|
||||
@ -376,10 +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(acceptor.clone())
|
||||
.openssl_with_config(acceptor.clone(), acceptor_config)
|
||||
})?;
|
||||
|
||||
Ok(self)
|
||||
@ -434,10 +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(config.clone())
|
||||
.rustls_with_config(config.clone(), acceptor_config)
|
||||
})?;
|
||||
|
||||
Ok(self)
|
||||
|
Reference in New Issue
Block a user