Skip to main content

hyper_boring/
lib.rs

1//! Hyper SSL support via BoringSSL.
2#![warn(missing_docs)]
3
4use std::fmt;
5use tokio_boring::SslStream;
6
7mod v1;
8
9pub use self::v1::*;
10
11/// Settings for [`HttpsLayer`]
12pub struct HttpsLayerSettings {
13    session_cache_capacity: usize,
14}
15
16impl HttpsLayerSettings {
17    /// Constructs an [`HttpsLayerSettingsBuilder`] for configuring settings
18    #[must_use]
19    pub fn builder() -> HttpsLayerSettingsBuilder {
20        HttpsLayerSettingsBuilder(HttpsLayerSettings::default())
21    }
22}
23
24impl Default for HttpsLayerSettings {
25    fn default() -> Self {
26        Self {
27            session_cache_capacity: 8,
28        }
29    }
30}
31
32/// Builder for [`HttpsLayerSettings`]
33pub struct HttpsLayerSettingsBuilder(HttpsLayerSettings);
34
35impl HttpsLayerSettingsBuilder {
36    /// Sets maximum number of sessions to cache. Session capacity is per session key (domain).
37    /// Defaults to 8.
38    pub fn set_session_cache_capacity(&mut self, capacity: usize) {
39        self.0.session_cache_capacity = capacity;
40    }
41
42    /// Consumes the builder, returning a new [`HttpsLayerSettings`]
43    #[must_use]
44    pub fn build(self) -> HttpsLayerSettings {
45        self.0
46    }
47}
48
49/// A stream which may be wrapped with TLS.
50pub enum MaybeHttpsStream<T> {
51    /// A raw HTTP stream.
52    Http(T),
53    /// An SSL-wrapped HTTP stream.
54    Https(SslStream<T>),
55}
56
57impl<T> fmt::Debug for MaybeHttpsStream<T> {
58    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59        match *self {
60            MaybeHttpsStream::Http(..) => f.pad("Http(..)"),
61            MaybeHttpsStream::Https(..) => f.pad("Https(..)"),
62        }
63    }
64}