diff --git a/src/client/connector.rs b/src/client/connector.rs index 32426e0a..3f4916af 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -290,7 +290,7 @@ impl Default for ClientConnector { feature = "ssl", feature = "tls", feature = "rust-tls", - ),))] + )))] { () } diff --git a/src/server/builder.rs b/src/server/builder.rs index 8c0a0f62..c9a97af3 100644 --- a/src/server/builder.rs +++ b/src/server/builder.rs @@ -32,6 +32,25 @@ where no_client_timer: bool, } +impl HttpServiceBuilder> +where + Io: IoStream + Send, + F: Fn() -> H + Send + Clone + 'static, + H: IntoHttpHandler, + A: AcceptorServiceFactory, + ::InitError: fmt::Debug, +{ + /// Create http service builder with default pipeline factory + pub fn with_default_pipeline(factory: F, acceptor: A) -> Self { + Self { + factory, + acceptor, + pipeline: DefaultPipelineFactory::new(), + no_client_timer: false, + } + } +} + impl HttpServiceBuilder where F: Fn() -> H + Send + Clone + 'static, diff --git a/src/server/http.rs b/src/server/http.rs index 034f903e..6344771b 100644 --- a/src/server/http.rs +++ b/src/server/http.rs @@ -520,6 +520,21 @@ impl H + Send + Clone> HttpServer { self.start(); sys.run(); } + + /// Register current http server as actix-net's server service + pub fn register(self, mut srv: Server) -> Server { + for socket in self.sockets { + srv = socket.handler.register( + srv, + socket.lst, + self.host.clone(), + socket.addr, + self.keep_alive.clone(), + self.client_timeout, + ); + } + srv + } } fn create_tcp_listener( diff --git a/src/server/ssl/mod.rs b/src/server/ssl/mod.rs index 1d6b55b1..c09573fe 100644 --- a/src/server/ssl/mod.rs +++ b/src/server/ssl/mod.rs @@ -1,7 +1,7 @@ #[cfg(any(feature = "alpn", feature = "ssl"))] mod openssl; #[cfg(any(feature = "alpn", feature = "ssl"))] -pub use self::openssl::*; +pub use self::openssl::{openssl_acceptor_with_flags, OpensslAcceptor}; #[cfg(feature = "tls")] mod nativetls; diff --git a/src/server/ssl/openssl.rs b/src/server/ssl/openssl.rs index 34315523..590dc0bb 100644 --- a/src/server/ssl/openssl.rs +++ b/src/server/ssl/openssl.rs @@ -1,14 +1,34 @@ use std::net::Shutdown; use std::{io, time}; +use actix_net::ssl; use openssl::ssl::{AlpnError, SslAcceptor, SslAcceptorBuilder}; +use tokio_io::{AsyncRead, AsyncWrite}; use tokio_openssl::SslStream; use server::{IoStream, ServerFlags}; -/// Configure `SslAcceptorBuilder` with enabled `HTTP/2` and `HTTP1.1` support. -pub fn openssl_acceptor(builder: SslAcceptorBuilder) -> io::Result { - openssl_acceptor_with_flags(builder, ServerFlags::HTTP1 | ServerFlags::HTTP2) +/// Support `SSL` connections via openssl package +/// +/// `ssl` feature enables `OpensslAcceptor` type +pub struct OpensslAcceptor { + _t: ssl::OpensslAcceptor, +} + +impl OpensslAcceptor { + /// Create `OpensslAcceptor` with enabled `HTTP/2` and `HTTP1.1` support. + pub fn new(builder: SslAcceptorBuilder) -> io::Result> { + OpensslAcceptor::with_flags(builder, ServerFlags::HTTP1 | ServerFlags::HTTP2) + } + + /// Create `OpensslAcceptor` with custom server flags. + pub fn with_flags( + mut builder: SslAcceptorBuilder, flags: ServerFlags, + ) -> io::Result> { + let acceptor = openssl_acceptor_with_flags(builder, flags)?; + + Ok(ssl::OpensslAcceptor::new(acceptor)) + } } /// Configure `SslAcceptorBuilder` with custom server flags.