HttpsLayerSettings

This commit is contained in:
Eric Rosenberg 2023-12-01 16:52:29 +00:00 committed by Rushil Mehra
parent 8db6134c75
commit 2cee0af3d2
1 changed files with 21 additions and 8 deletions

View File

@ -87,6 +87,20 @@ pub struct HttpsLayer {
inner: Inner, inner: Inner,
} }
/// Settings for [`HttpsLayer`]
pub struct HttpsLayerSettings {
/// Maximum number of sessions to cache. Session capacity is per session key (domain).
pub session_cache_capacity: usize,
}
impl Default for HttpsLayerSettings {
fn default() -> Self {
Self {
session_cache_capacity: 8,
}
}
}
impl HttpsLayer { impl HttpsLayer {
/// Creates a new `HttpsLayer` with default settings. /// Creates a new `HttpsLayer` with default settings.
/// ///
@ -103,18 +117,17 @@ impl HttpsLayer {
/// ///
/// The session cache configuration of `ssl` will be overwritten. /// The session cache configuration of `ssl` will be overwritten.
pub fn with_connector(ssl: SslConnectorBuilder) -> Result<HttpsLayer, ErrorStack> { pub fn with_connector(ssl: SslConnectorBuilder) -> Result<HttpsLayer, ErrorStack> {
Self::with_connector_and_capacity(ssl, 8) Self::with_connector_and_settings(ssl, Default::default())
} }
/// Creates a new `HttpsLayer` with session capacity. /// Creates a new `HttpsLayer` with settings
/// pub fn with_connector_and_settings(
/// The session cache configuration of `ssl` will be overwritten. Session capacity is per
/// session key (domain).
pub fn with_connector_and_capacity(
mut ssl: SslConnectorBuilder, mut ssl: SslConnectorBuilder,
capacity: usize, settings: HttpsLayerSettings,
) -> Result<HttpsLayer, ErrorStack> { ) -> Result<HttpsLayer, ErrorStack> {
let cache = Arc::new(Mutex::new(SessionCache::with_capacity(capacity))); let cache = Arc::new(Mutex::new(SessionCache::with_capacity(
settings.session_cache_capacity,
)));
ssl.set_session_cache_mode(SslSessionCacheMode::CLIENT); ssl.set_session_cache_mode(SslSessionCacheMode::CLIENT);