mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
cleanup ServerFactory trait
This commit is contained in:
parent
a3cfc24232
commit
a63d3f9a7a
@ -351,28 +351,36 @@ where
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Start listening for incoming connections with supplied acceptor.
|
/// Start listening for incoming connections with supplied acceptor.
|
||||||
// #[doc(hidden)]
|
#[doc(hidden)]
|
||||||
// #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||||
// pub fn bind_with<S, A>(mut self, addr: S, acceptor: A) -> io::Result<Self>
|
pub fn bind_with<S, A>(mut self, addr: S, acceptor: A) -> io::Result<Self>
|
||||||
// where
|
where
|
||||||
// S: net::ToSocketAddrs,
|
S: net::ToSocketAddrs,
|
||||||
// A: AcceptorService<TcpStream> + Send + 'static,
|
A: AcceptorServiceFactory,
|
||||||
// {
|
{
|
||||||
// let sockets = self.bind2(addr)?;
|
let sockets = self.bind2(addr)?;
|
||||||
|
|
||||||
// for lst in sockets {
|
for lst in sockets {
|
||||||
// let token = Token(self.handlers.len());
|
let addr = lst.local_addr().unwrap();
|
||||||
// let addr = lst.local_addr().unwrap();
|
self.sockets.push(Socket {
|
||||||
// self.handlers.push(Box::new(StreamHandler::new(
|
lst,
|
||||||
// lst.local_addr().unwrap(),
|
addr,
|
||||||
// acceptor.clone(),
|
scheme: "https",
|
||||||
// )));
|
handler: Box::new(HttpServiceBuilder::new(
|
||||||
// self.sockets.push(Socket { lst, addr, token })
|
acceptor.clone(),
|
||||||
// }
|
DefaultPipelineFactory::new(
|
||||||
|
self.factory.clone(),
|
||||||
|
self.host.clone(),
|
||||||
|
addr,
|
||||||
|
self.keep_alive,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Ok(self)
|
Ok(self)
|
||||||
// }
|
}
|
||||||
|
|
||||||
fn bind2<S: net::ToSocketAddrs>(
|
fn bind2<S: net::ToSocketAddrs>(
|
||||||
&self, addr: S,
|
&self, addr: S,
|
||||||
@ -416,25 +424,50 @@ where
|
|||||||
// self.bind_with(addr, NativeTlsAcceptor::new(acceptor))
|
// self.bind_with(addr, NativeTlsAcceptor::new(acceptor))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[cfg(feature = "alpn")]
|
#[cfg(any(feature = "alpn", feature = "ssl"))]
|
||||||
// /// Start listening for incoming tls connections.
|
/// Start listening for incoming tls connections.
|
||||||
// ///
|
///
|
||||||
// /// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
// pub fn bind_ssl<S>(self, addr: S, builder: SslAcceptorBuilder) -> io::Result<Self>
|
pub fn bind_ssl<S>(
|
||||||
// where
|
mut self, addr: S, builder: SslAcceptorBuilder,
|
||||||
// S: net::ToSocketAddrs,
|
) -> io::Result<Self>
|
||||||
// {
|
where
|
||||||
// use super::{OpensslAcceptor, ServerFlags};
|
S: net::ToSocketAddrs,
|
||||||
|
{
|
||||||
|
use super::{openssl_acceptor_with_flags, ServerFlags};
|
||||||
|
|
||||||
// // alpn support
|
let sockets = self.bind2(addr)?;
|
||||||
// let flags = if !self.no_http2 {
|
|
||||||
// ServerFlags::HTTP1
|
|
||||||
// } else {
|
|
||||||
// ServerFlags::HTTP1 | ServerFlags::HTTP2
|
|
||||||
// };
|
|
||||||
|
|
||||||
// self.bind_with(addr, OpensslAcceptor::with_flags(builder, flags)?)
|
// alpn support
|
||||||
// }
|
let flags = if !self.no_http2 {
|
||||||
|
ServerFlags::HTTP1
|
||||||
|
} else {
|
||||||
|
ServerFlags::HTTP1 | ServerFlags::HTTP2
|
||||||
|
};
|
||||||
|
|
||||||
|
let acceptor = openssl_acceptor_with_flags(builder, flags)?;
|
||||||
|
|
||||||
|
for lst in sockets {
|
||||||
|
let addr = lst.local_addr().unwrap();
|
||||||
|
let accpt = acceptor.clone();
|
||||||
|
self.sockets.push(Socket {
|
||||||
|
lst,
|
||||||
|
addr,
|
||||||
|
scheme: "https",
|
||||||
|
handler: Box::new(HttpServiceBuilder::new(
|
||||||
|
move || ssl::OpensslAcceptor::new(accpt.clone()).map_err(|_| ()),
|
||||||
|
DefaultPipelineFactory::new(
|
||||||
|
self.factory.clone(),
|
||||||
|
self.host.clone(),
|
||||||
|
addr,
|
||||||
|
self.keep_alive,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
// #[cfg(feature = "rust-tls")]
|
// #[cfg(feature = "rust-tls")]
|
||||||
// /// Start listening for incoming tls connections.
|
// /// Start listening for incoming tls connections.
|
||||||
@ -500,13 +533,7 @@ impl<H: IntoHttpHandler, F: Fn() -> Vec<H> + Send + Clone> HttpServer<H, F> {
|
|||||||
let sockets = mem::replace(&mut self.sockets, Vec::new());
|
let sockets = mem::replace(&mut self.sockets, Vec::new());
|
||||||
|
|
||||||
for socket in sockets {
|
for socket in sockets {
|
||||||
let Socket {
|
srv = socket.handler.register(srv, socket.lst);
|
||||||
lst,
|
|
||||||
handler,
|
|
||||||
addr: _,
|
|
||||||
scheme: _,
|
|
||||||
} = socket;
|
|
||||||
srv = handler.register(srv, lst, self.host.clone(), self.keep_alive);
|
|
||||||
}
|
}
|
||||||
srv.start()
|
srv.start()
|
||||||
}
|
}
|
||||||
@ -700,10 +727,7 @@ trait ServiceFactory<H>
|
|||||||
where
|
where
|
||||||
H: IntoHttpHandler,
|
H: IntoHttpHandler,
|
||||||
{
|
{
|
||||||
fn register(
|
fn register(&self, server: Server, lst: net::TcpListener) -> Server;
|
||||||
&self, server: Server, lst: net::TcpListener, host: Option<String>,
|
|
||||||
keep_alive: KeepAlive,
|
|
||||||
) -> Server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SimpleFactory<H, F, P>
|
struct SimpleFactory<H, F, P>
|
||||||
@ -737,10 +761,7 @@ where
|
|||||||
F: Fn() -> Vec<H> + Send + Clone + 'static,
|
F: Fn() -> Vec<H> + Send + Clone + 'static,
|
||||||
P: HttpPipelineFactory<Io = TcpStream>,
|
P: HttpPipelineFactory<Io = TcpStream>,
|
||||||
{
|
{
|
||||||
fn register(
|
fn register(&self, server: Server, lst: net::TcpListener) -> Server {
|
||||||
&self, server: Server, lst: net::TcpListener, _host: Option<String>,
|
|
||||||
_keep_alive: KeepAlive,
|
|
||||||
) -> Server {
|
|
||||||
let pipeline = self.pipeline.clone();
|
let pipeline = self.pipeline.clone();
|
||||||
server.listen(lst, move || pipeline.create())
|
server.listen(lst, move || pipeline.create())
|
||||||
}
|
}
|
||||||
@ -814,10 +835,7 @@ where
|
|||||||
P: HttpPipelineFactory<Io = A::Io>,
|
P: HttpPipelineFactory<Io = A::Io>,
|
||||||
H: IntoHttpHandler,
|
H: IntoHttpHandler,
|
||||||
{
|
{
|
||||||
fn register(
|
fn register(&self, server: Server, lst: net::TcpListener) -> Server {
|
||||||
&self, server: Server, lst: net::TcpListener, _host: Option<String>,
|
|
||||||
_keep_alive: KeepAlive,
|
|
||||||
) -> Server {
|
|
||||||
server.listen(lst, self.finish())
|
server.listen(lst, self.finish())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ extern crate h2;
|
|||||||
extern crate http as modhttp;
|
extern crate http as modhttp;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
extern crate tokio_current_thread;
|
||||||
extern crate tokio_reactor;
|
extern crate tokio_reactor;
|
||||||
extern crate tokio_tcp;
|
extern crate tokio_tcp;
|
||||||
extern crate tokio_current_thread as current_thread;
|
extern crate tokio_current_thread as current_thread;
|
||||||
|
Loading…
Reference in New Issue
Block a user