mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
add HttpServer::register() function, allows to register services in actix net server
This commit is contained in:
parent
4aac3d6a92
commit
5966ee6192
@ -290,7 +290,7 @@ impl Default for ClientConnector {
|
||||
feature = "ssl",
|
||||
feature = "tls",
|
||||
feature = "rust-tls",
|
||||
),))]
|
||||
)))]
|
||||
{
|
||||
()
|
||||
}
|
||||
|
@ -32,6 +32,25 @@ where
|
||||
no_client_timer: bool,
|
||||
}
|
||||
|
||||
impl<F, H, A, Io> HttpServiceBuilder<F, H, A, DefaultPipelineFactory<H::Handler, Io>>
|
||||
where
|
||||
Io: IoStream + Send,
|
||||
F: Fn() -> H + Send + Clone + 'static,
|
||||
H: IntoHttpHandler,
|
||||
A: AcceptorServiceFactory,
|
||||
<A::NewService as NewService>::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<F, H, A, P> HttpServiceBuilder<F, H, A, P>
|
||||
where
|
||||
F: Fn() -> H + Send + Clone + 'static,
|
||||
|
@ -520,6 +520,21 @@ impl<H: IntoHttpHandler, F: Fn() -> H + Send + Clone> HttpServer<H, F> {
|
||||
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(
|
||||
|
@ -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;
|
||||
|
@ -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<SslAcceptor> {
|
||||
openssl_acceptor_with_flags(builder, ServerFlags::HTTP1 | ServerFlags::HTTP2)
|
||||
/// Support `SSL` connections via openssl package
|
||||
///
|
||||
/// `ssl` feature enables `OpensslAcceptor` type
|
||||
pub struct OpensslAcceptor<T> {
|
||||
_t: ssl::OpensslAcceptor<T>,
|
||||
}
|
||||
|
||||
impl<T: AsyncRead + AsyncWrite> OpensslAcceptor<T> {
|
||||
/// Create `OpensslAcceptor` with enabled `HTTP/2` and `HTTP1.1` support.
|
||||
pub fn new(builder: SslAcceptorBuilder) -> io::Result<ssl::OpensslAcceptor<T>> {
|
||||
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<ssl::OpensslAcceptor<T>> {
|
||||
let acceptor = openssl_acceptor_with_flags(builder, flags)?;
|
||||
|
||||
Ok(ssl::OpensslAcceptor::new(acceptor))
|
||||
}
|
||||
}
|
||||
|
||||
/// Configure `SslAcceptorBuilder` with custom server flags.
|
||||
|
Loading…
Reference in New Issue
Block a user