1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

Merge pull request #225 from mitsuhiko/feature/addrs-with-scheme

Support returning addresses plus scheme from the server
This commit is contained in:
Nikolay Kim 2018-05-16 11:02:15 -07:00 committed by GitHub
commit d8ae8c3821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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,

View File

@ -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",
}
}
}