1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +01: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 // re-exports
pub use http::{Method, StatusCode, Version}; pub use http::{Method, StatusCode, Version};
#[doc(hidden)]
#[cfg(feature="tls")]
pub use native_tls::Pkcs12;
#[cfg(feature="openssl")] #[cfg(feature="openssl")]
pub(crate) const HAS_OPENSSL: bool = true; pub(crate) const HAS_OPENSSL: bool = true;
#[cfg(not(feature="openssl"))] #[cfg(not(feature="openssl"))]

View File

@ -333,21 +333,12 @@ impl<H: IntoHttpHandler> HttpServer<H>
impl<H: IntoHttpHandler> HttpServer<H> impl<H: IntoHttpHandler> HttpServer<H>
{ {
/// Start listening for incoming tls connections. /// 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() { if self.sockets.is_empty() {
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound")) Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
} else { } else {
let addrs: Vec<(net::SocketAddr, net::TcpListener)> = self.sockets.drain().collect(); let addrs: Vec<(net::SocketAddr, net::TcpListener)> = self.sockets.drain().collect();
let settings = ServerSettings::new(Some(addrs[0].0), &self.host, false); 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)); let workers = self.start_workers(&settings, &StreamHandlerType::Tls(acceptor));
// start acceptors threads // start acceptors threads