diff --git a/src/net.rs b/src/net.rs index e913467e95..6495964c3d 100644 --- a/src/net.rs +++ b/src/net.rs @@ -410,7 +410,9 @@ impl NetworkConnector for F where F: Fn(&str, u16, &str) -> io::Result ::Result; } +/// An abstraction to allow any SSL implementation to be used with client-side HttpsStreams. +pub trait SslClient { + /// The protected stream. + type Stream: NetworkStream + Send + Clone; + /// Wrap a client stream with SSL. + fn wrap_client(&self, stream: HttpStream, host: &str) -> ::Result; +} + +/// An abstraction to allow any SSL implementation to be used with server-side HttpsStreams. +pub trait SslServer { + /// The protected stream. + type Stream: NetworkStream + Send + Clone; + /// Wrap a server stream with SSL. + fn wrap_server(&self, stream: HttpStream) -> ::Result; +} + +impl SslClient for S { + type Stream = ::Stream; + + fn wrap_client(&self, stream: HttpStream, host: &str) -> ::Result { + Ssl::wrap_client(self, stream, host) + } +} + +impl SslServer for S { + type Stream = ::Stream; + + fn wrap_server(&self, stream: HttpStream) -> ::Result { + Ssl::wrap_server(self, stream) + } +} + /// A stream over the HTTP protocol, possibly protected by SSL. #[derive(Debug, Clone)] pub enum HttpsStream { @@ -493,7 +527,7 @@ impl NetworkStream for HttpsStream { /// A Http Listener over SSL. #[derive(Clone)] -pub struct HttpsListener { +pub struct HttpsListener { listener: HttpListener, ssl: S, } @@ -516,7 +550,7 @@ impl HttpsListener { } } -impl NetworkListener for HttpsListener { +impl NetworkListener for HttpsListener { type Stream = S::Stream; #[inline] @@ -532,18 +566,18 @@ impl NetworkListener for HttpsListener { /// A connector that can protect HTTP streams using SSL. #[derive(Debug, Default)] -pub struct HttpsConnector { +pub struct HttpsConnector { ssl: S } -impl HttpsConnector { +impl HttpsConnector { /// Create a new connector using the provided SSL implementation. pub fn new(s: S) -> HttpsConnector { HttpsConnector { ssl: s } } } -impl NetworkConnector for HttpsConnector { +impl NetworkConnector for HttpsConnector { type Stream = HttpsStream; fn connect(&self, host: &str, port: u16, scheme: &str) -> ::Result {