1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-09-21 02:50:10 +00:00

simplify HttpServer::start_tls() method

This commit is contained in:
Nikolay Kim 2018-02-10 11:34:54 -08:00
parent e3081306da
commit 856055c6ca
2 changed files with 1 additions and 14 deletions

View file

@ -138,10 +138,6 @@ pub use server::HttpServer;
// re-exports
pub use http::{Method, StatusCode, Version};
#[doc(hidden)]
#[cfg(feature="tls")]
pub use native_tls::Pkcs12;
#[cfg(feature="openssl")]
pub(crate) const HAS_OPENSSL: bool = true;
#[cfg(not(feature="openssl"))]

View file

@ -333,21 +333,12 @@ impl<H: IntoHttpHandler> HttpServer<H>
impl<H: IntoHttpHandler> HttpServer<H>
{
/// Start listening for incoming tls connections.
pub fn start_tls(mut self, pkcs12: ::Pkcs12) -> io::Result<SyncAddress<Self>> {
pub fn start_tls(mut self, acceptor: TlsAcceptor) -> io::Result<SyncAddress<Self>> {
if self.sockets.is_empty() {
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
} else {
let addrs: Vec<(net::SocketAddr, net::TcpListener)> = self.sockets.drain().collect();
let settings = ServerSettings::new(Some(addrs[0].0), &self.host, false);
let acceptor = match TlsAcceptor::builder(pkcs12) {
Ok(builder) => {
match builder.build() {
Ok(acceptor) => acceptor,
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err))
}
}
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err))
};
let workers = self.start_workers(&settings, &StreamHandlerType::Tls(acceptor));
// start acceptors threads