diff --git a/src/server/srv.rs b/src/server/srv.rs index c76ec749..30b7b4e4 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -211,6 +211,16 @@ where self.sockets.iter().map(|s| s.addr).collect() } + /// Get addresses of bound sockets and the scheme for it. + /// + /// This is useful when the server is bound from different sources + /// with some sockets listening on http and some listening on https + /// and the user should be presented with an enumeration of which + /// socket requires which protocol. + pub fn addrs_with_scheme(&self) -> Vec<(net::SocketAddr, &str)> { + self.sockets.iter().map(|s| (s.addr, s.tp.scheme())).collect() + } + /// Use listener for accepting incoming connection requests /// /// HttpServer does not change any configuration for TcpListener, diff --git a/src/server/worker.rs b/src/server/worker.rs index 67f4645c..a926a6c8 100644 --- a/src/server/worker.rs +++ b/src/server/worker.rs @@ -239,4 +239,14 @@ impl StreamHandlerType { } } } + + pub(crate) fn scheme(&self) -> &'static str { + match *self { + StreamHandlerType::Normal => "http", + #[cfg(feature = "tls")] + StreamHandlerType::Tls(ref acceptor) => "https", + #[cfg(feature = "alpn")] + StreamHandlerType::Alpn(ref acceptor) => "https", + } + } }