mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 13:51:50 +01:00
rename and simplify ServiceFactory trait
This commit is contained in:
parent
d57579d700
commit
85445ea809
@ -2,7 +2,7 @@ use std::marker::PhantomData;
|
||||
use std::net;
|
||||
|
||||
use actix_net::either::Either;
|
||||
use actix_net::server;
|
||||
use actix_net::server::{Server, ServiceFactory};
|
||||
use actix_net::service::{NewService, NewServiceExt};
|
||||
|
||||
use super::acceptor::{AcceptorServiceFactory, AcceptorTimeout, TcpAcceptor};
|
||||
@ -11,14 +11,11 @@ use super::service::HttpService;
|
||||
use super::settings::{ServerSettings, WorkerSettings};
|
||||
use super::{IoStream, KeepAlive};
|
||||
|
||||
pub(crate) trait ServiceFactory<H>
|
||||
where
|
||||
H: IntoHttpHandler,
|
||||
{
|
||||
pub(crate) trait ServiceProvider {
|
||||
fn register(
|
||||
&self, server: server::Server, lst: net::TcpListener, host: Option<String>,
|
||||
&self, server: Server, lst: net::TcpListener, host: Option<String>,
|
||||
addr: net::SocketAddr, keep_alive: KeepAlive, client_timeout: usize,
|
||||
) -> server::Server;
|
||||
) -> Server;
|
||||
}
|
||||
|
||||
pub struct HttpServiceBuilder<F, H, A, P>
|
||||
@ -73,7 +70,7 @@ where
|
||||
fn finish(
|
||||
&self, host: Option<String>, addr: net::SocketAddr, keep_alive: KeepAlive,
|
||||
client_timeout: usize,
|
||||
) -> impl server::ServiceFactory {
|
||||
) -> impl ServiceFactory {
|
||||
let factory = self.factory.clone();
|
||||
let pipeline = self.pipeline.clone();
|
||||
let acceptor = self.acceptor.clone();
|
||||
@ -119,7 +116,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, H, A, P> ServiceFactory<H> for HttpServiceBuilder<F, H, A, P>
|
||||
impl<F, H, A, P> ServiceProvider for HttpServiceBuilder<F, H, A, P>
|
||||
where
|
||||
F: Fn() -> H + Send + Clone + 'static,
|
||||
A: AcceptorServiceFactory,
|
||||
@ -127,9 +124,9 @@ where
|
||||
H: IntoHttpHandler,
|
||||
{
|
||||
fn register(
|
||||
&self, server: server::Server, lst: net::TcpListener, host: Option<String>,
|
||||
&self, server: Server, lst: net::TcpListener, host: Option<String>,
|
||||
addr: net::SocketAddr, keep_alive: KeepAlive, client_timeout: usize,
|
||||
) -> server::Server {
|
||||
) -> Server {
|
||||
server.listen2(
|
||||
"actix-web",
|
||||
lst,
|
||||
|
@ -528,6 +528,7 @@ mod tests {
|
||||
WorkerSettings::<HttpApplication>::new(
|
||||
App::new().into_handler(),
|
||||
KeepAlive::Os,
|
||||
5000,
|
||||
ServerSettings::default(),
|
||||
)
|
||||
}
|
||||
|
@ -20,14 +20,14 @@ use openssl::ssl::SslAcceptorBuilder;
|
||||
|
||||
use super::acceptor::{AcceptorServiceFactory, DefaultAcceptor};
|
||||
use super::builder::DefaultPipelineFactory;
|
||||
use super::builder::{HttpServiceBuilder, ServiceFactory};
|
||||
use super::builder::{HttpServiceBuilder, ServiceProvider};
|
||||
use super::{IntoHttpHandler, IoStream, KeepAlive};
|
||||
|
||||
struct Socket<H: IntoHttpHandler> {
|
||||
struct Socket {
|
||||
scheme: &'static str,
|
||||
lst: net::TcpListener,
|
||||
addr: net::SocketAddr,
|
||||
handler: Box<ServiceFactory<H>>,
|
||||
handler: Box<ServiceProvider>,
|
||||
}
|
||||
|
||||
/// An HTTP Server
|
||||
@ -52,7 +52,7 @@ where
|
||||
maxconn: usize,
|
||||
maxconnrate: usize,
|
||||
client_timeout: usize,
|
||||
sockets: Vec<Socket<H>>,
|
||||
sockets: Vec<Socket>,
|
||||
}
|
||||
|
||||
impl<H, F> HttpServer<H, F>
|
||||
|
@ -330,8 +330,12 @@ mod tests {
|
||||
let mut rt = current_thread::Runtime::new().unwrap();
|
||||
|
||||
let _ = rt.block_on(future::lazy(|| {
|
||||
let settings =
|
||||
WorkerSettings::<()>::new((), KeepAlive::Os, ServerSettings::default());
|
||||
let settings = WorkerSettings::<()>::new(
|
||||
(),
|
||||
KeepAlive::Os,
|
||||
0,
|
||||
ServerSettings::default(),
|
||||
);
|
||||
let mut buf1 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10);
|
||||
settings.set_date(&mut buf1, true);
|
||||
let mut buf2 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10);
|
||||
|
Loading…
x
Reference in New Issue
Block a user