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