mirror of https://github.com/fafhrd91/actix-web
remove B generic
This commit is contained in:
parent
a9e84c5895
commit
4b098d31ae
|
@ -2,9 +2,7 @@ use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
cmp, fmt,
|
cmp, fmt,
|
||||||
future::Future,
|
future::Future,
|
||||||
io,
|
io, net,
|
||||||
marker::PhantomData,
|
|
||||||
net,
|
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
@ -23,7 +21,7 @@ use actix_tls::accept::openssl::reexports::{AlpnError, SslAcceptor, SslAcceptorB
|
||||||
#[cfg(feature = "rustls")]
|
#[cfg(feature = "rustls")]
|
||||||
use actix_tls::accept::rustls::reexports::ServerConfig as RustlsServerConfig;
|
use actix_tls::accept::rustls::reexports::ServerConfig as RustlsServerConfig;
|
||||||
|
|
||||||
use crate::{config::AppConfig, Error, HttpResponse};
|
use crate::{config::AppConfig, Error};
|
||||||
|
|
||||||
struct Socket {
|
struct Socket {
|
||||||
scheme: &'static str,
|
scheme: &'static str,
|
||||||
|
@ -54,7 +52,7 @@ struct Config {
|
||||||
/// .await
|
/// .await
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct HttpServer<SF = (), B = ()> {
|
pub struct HttpServer<SF> {
|
||||||
pub(super) factory: SF,
|
pub(super) factory: SF,
|
||||||
config: Arc<Mutex<Config>>,
|
config: Arc<Mutex<Config>>,
|
||||||
backlog: u32,
|
backlog: u32,
|
||||||
|
@ -62,10 +60,9 @@ pub struct HttpServer<SF = (), B = ()> {
|
||||||
builder: ServerBuilder,
|
builder: ServerBuilder,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
on_connect_fn: Option<Arc<dyn Fn(&dyn Any, &mut Extensions) + Send + Sync>>,
|
on_connect_fn: Option<Arc<dyn Fn(&dyn Any, &mut Extensions) + Send + Sync>>,
|
||||||
_phantom: PhantomData<(B,)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpServer {
|
impl HttpServer<()> {
|
||||||
/// Create new HTTP server with application factory
|
/// Create new HTTP server with application factory
|
||||||
pub fn new<F, I, SF, B>(
|
pub fn new<F, I, SF, B>(
|
||||||
factory_fn: F,
|
factory_fn: F,
|
||||||
|
@ -73,12 +70,11 @@ impl HttpServer {
|
||||||
impl ServiceFactory<
|
impl ServiceFactory<
|
||||||
Request,
|
Request,
|
||||||
Config = AppConfig,
|
Config = AppConfig,
|
||||||
Error = HttpResponse,
|
Error = Response<BoxBody>,
|
||||||
InitError = SF::InitError,
|
InitError = SF::InitError,
|
||||||
Response = SF::Response,
|
Response = Response<B>,
|
||||||
> + Send
|
> + Send
|
||||||
+ Clone,
|
+ Clone,
|
||||||
B,
|
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
F: FnOnce() -> I + Send + Clone + 'static,
|
F: FnOnce() -> I + Send + Clone + 'static,
|
||||||
|
@ -93,7 +89,8 @@ impl HttpServer {
|
||||||
let factory_fn = factory_fn.clone();
|
let factory_fn = factory_fn.clone();
|
||||||
async move { factory_fn().into_factory().new_service(cfg).await }
|
async move { factory_fn().into_factory().new_service(cfg).await }
|
||||||
})
|
})
|
||||||
.map_err(|err| err.into().error_response());
|
.map(|resp| resp.into())
|
||||||
|
.map_err(|err| err.into().error_response().into());
|
||||||
|
|
||||||
HttpServer::new2(factory)
|
HttpServer::new2(factory)
|
||||||
}
|
}
|
||||||
|
@ -104,12 +101,11 @@ impl HttpServer {
|
||||||
impl ServiceFactory<
|
impl ServiceFactory<
|
||||||
Request,
|
Request,
|
||||||
Config = AppConfig,
|
Config = AppConfig,
|
||||||
Error = HttpResponse,
|
Error = Response<BoxBody>,
|
||||||
InitError = SF::InitError,
|
InitError = SF::InitError,
|
||||||
Response = SF::Response,
|
Response = Response<B>,
|
||||||
> + Send
|
> + Send
|
||||||
+ Clone,
|
+ Clone,
|
||||||
B,
|
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
F: FnOnce() -> Fut + Send + Clone + 'static,
|
F: FnOnce() -> Fut + Send + Clone + 'static,
|
||||||
|
@ -125,18 +121,24 @@ impl HttpServer {
|
||||||
let factory_fn = factory_fn.clone();
|
let factory_fn = factory_fn.clone();
|
||||||
async move { factory_fn().await.into_factory().new_service(cfg).await }
|
async move { factory_fn().await.into_factory().new_service(cfg).await }
|
||||||
})
|
})
|
||||||
.map_err(|err| err.into().error_response());
|
.map(|resp| resp.into())
|
||||||
|
.map_err(|err| err.into().error_response().into());
|
||||||
|
|
||||||
HttpServer::new2(factory)
|
HttpServer::new2(factory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SF, B> HttpServer<SF, B>
|
impl<SF, B> HttpServer<SF>
|
||||||
where
|
where
|
||||||
SF: ServiceFactory<Request, Config = AppConfig> + Send + Clone + 'static,
|
SF: ServiceFactory<
|
||||||
SF::Error: Into<Response<BoxBody>>,
|
Request,
|
||||||
|
Config = AppConfig,
|
||||||
|
Response = Response<B>,
|
||||||
|
Error = Response<BoxBody>,
|
||||||
|
> + Send
|
||||||
|
+ Clone
|
||||||
|
+ 'static,
|
||||||
SF::InitError: fmt::Debug,
|
SF::InitError: fmt::Debug,
|
||||||
SF::Response: Into<Response<B>>,
|
|
||||||
B: MessageBody + 'static,
|
B: MessageBody + 'static,
|
||||||
{
|
{
|
||||||
fn new2(factory: SF) -> Self {
|
fn new2(factory: SF) -> Self {
|
||||||
|
@ -152,7 +154,6 @@ where
|
||||||
sockets: Vec::new(),
|
sockets: Vec::new(),
|
||||||
builder: ServerBuilder::default(),
|
builder: ServerBuilder::default(),
|
||||||
on_connect_fn: None,
|
on_connect_fn: None,
|
||||||
_phantom: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +178,6 @@ where
|
||||||
sockets: self.sockets,
|
sockets: self.sockets,
|
||||||
builder: self.builder,
|
builder: self.builder,
|
||||||
on_connect_fn: Some(Arc::new(f)),
|
on_connect_fn: Some(Arc::new(f)),
|
||||||
_phantom: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue