From 2cee0af3d22abc517a72ef18216fb8b67c6d3900 Mon Sep 17 00:00:00 2001 From: Eric Rosenberg Date: Fri, 1 Dec 2023 16:52:29 +0000 Subject: [PATCH] HttpsLayerSettings --- hyper-boring/src/lib.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/hyper-boring/src/lib.rs b/hyper-boring/src/lib.rs index bbd60b77..4c4e569d 100644 --- a/hyper-boring/src/lib.rs +++ b/hyper-boring/src/lib.rs @@ -87,6 +87,20 @@ pub struct HttpsLayer { 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 { /// Creates a new `HttpsLayer` with default settings. /// @@ -103,18 +117,17 @@ impl HttpsLayer { /// /// The session cache configuration of `ssl` will be overwritten. pub fn with_connector(ssl: SslConnectorBuilder) -> Result { - Self::with_connector_and_capacity(ssl, 8) + Self::with_connector_and_settings(ssl, Default::default()) } - /// Creates a new `HttpsLayer` with session capacity. - /// - /// The session cache configuration of `ssl` will be overwritten. Session capacity is per - /// session key (domain). - pub fn with_connector_and_capacity( + /// Creates a new `HttpsLayer` with settings + pub fn with_connector_and_settings( mut ssl: SslConnectorBuilder, - capacity: usize, + settings: HttpsLayerSettings, ) -> Result { - 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);