1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

update service factory config

This commit is contained in:
Nikolay Kim 2019-12-02 21:37:13 +06:00
parent f4c01384ec
commit 068f047dd5
17 changed files with 47 additions and 47 deletions

View File

@ -415,7 +415,7 @@ impl ServiceFactory for Files {
type InitError = (); type InitError = ();
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>; type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
let mut srv = FilesService { let mut srv = FilesService {
directory: self.directory.clone(), directory: self.directory.clone(),
index: self.index.clone(), index: self.index.clone(),
@ -430,7 +430,7 @@ impl ServiceFactory for Files {
if let Some(ref default) = *self.default.borrow() { if let Some(ref default) = *self.default.borrow() {
default default
.new_service(&()) .new_service(())
.map(move |result| match result { .map(move |result| match result {
Ok(default) => { Ok(default) => {
srv.default = Some(default); srv.default = Some(default);
@ -1262,7 +1262,7 @@ mod tests {
.default_handler(|req: ServiceRequest| { .default_handler(|req: ServiceRequest| {
ok(req.into_response(HttpResponse::Ok().body("default content"))) ok(req.into_response(HttpResponse::Ok().body("default content")))
}) })
.new_service(&()) .new_service(())
.await .await
.unwrap(); .unwrap();
let req = TestRequest::with_uri("/missing").to_srv_request(); let req = TestRequest::with_uri("/missing").to_srv_request();

View File

@ -104,7 +104,7 @@ where
type Service = FramedAppService<T, S>; type Service = FramedAppService<T, S>;
type Future = CreateService<T, S>; type Future = CreateService<T, S>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
CreateService { CreateService {
fut: self fut: self
.services .services
@ -112,7 +112,7 @@ where
.map(|(path, service)| { .map(|(path, service)| {
CreateServiceItem::Future( CreateServiceItem::Future(
Some(path.clone()), Some(path.clone()),
service.new_service(&()), service.new_service(()),
) )
}) })
.collect(), .collect(),

View File

@ -56,8 +56,8 @@ where
type Service = BoxedHttpService<T::Request>; type Service = BoxedHttpService<T::Request>;
type Future = LocalBoxFuture<'static, Result<Self::Service, ()>>; type Future = LocalBoxFuture<'static, Result<Self::Service, ()>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
let fut = self.0.new_service(&()); let fut = self.0.new_service(());
async move { async move {
fut.await.map_err(|_| ()).map(|service| { fut.await.map_err(|_| ()).map(|service| {

View File

@ -113,7 +113,7 @@ where
type Service = FramedRouteService<Io, S, F, R, E>; type Service = FramedRouteService<Io, S, F, R, E>;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(FramedRouteService { ok(FramedRouteService {
handler: self.handler.clone(), handler: self.handler.clone(),
methods: self.methods.clone(), methods: self.methods.clone(),

View File

@ -33,7 +33,7 @@ impl<T, C> ServiceFactory for VerifyWebSockets<T, C> {
type Service = VerifyWebSockets<T, C>; type Service = VerifyWebSockets<T, C>;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &C) -> Self::Future { fn new_service(&self, _: C) -> Self::Future {
ok(VerifyWebSockets { _t: PhantomData }) ok(VerifyWebSockets { _t: PhantomData })
} }
} }
@ -83,7 +83,7 @@ where
type Service = SendError<T, R, E, C>; type Service = SendError<T, R, E, C>;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &C) -> Self::Future { fn new_service(&self, _: C) -> Self::Future {
ok(SendError(PhantomData)) ok(SendError(PhantomData))
} }
} }

View File

@ -17,7 +17,7 @@ impl ServiceFactory for ExpectHandler {
type InitError = Error; type InitError = Error;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(ExpectHandler) ok(ExpectHandler)
} }
} }

View File

@ -217,11 +217,11 @@ where
type Service = H1ServiceHandler<T, S::Service, B, X::Service, U::Service>; type Service = H1ServiceHandler<T, S::Service, B, X::Service, U::Service>;
type Future = H1ServiceResponse<T, S, B, X, U>; type Future = H1ServiceResponse<T, S, B, X, U>;
fn new_service(&self, cfg: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
H1ServiceResponse { H1ServiceResponse {
fut: self.srv.new_service(cfg), fut: self.srv.new_service(()),
fut_ex: Some(self.expect.new_service(cfg)), fut_ex: Some(self.expect.new_service(())),
fut_upg: self.upgrade.as_ref().map(|f| f.new_service(cfg)), fut_upg: self.upgrade.as_ref().map(|f| f.new_service(())),
expect: None, expect: None,
upgrade: None, upgrade: None,
on_connect: self.on_connect.clone(), on_connect: self.on_connect.clone(),
@ -450,7 +450,7 @@ where
type Service = OneRequestService<T>; type Service = OneRequestService<T>;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(OneRequestService { ok(OneRequestService {
_t: PhantomData, _t: PhantomData,
config: self.config.clone(), config: self.config.clone(),

View File

@ -20,7 +20,7 @@ impl<T> ServiceFactory for UpgradeHandler<T> {
type InitError = Error; type InitError = Error;
type Future = Ready<Result<Self::Service, Self::InitError>>; type Future = Ready<Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
unimplemented!() unimplemented!()
} }
} }

View File

@ -160,9 +160,9 @@ where
type Service = H2ServiceHandler<T, S::Service, B>; type Service = H2ServiceHandler<T, S::Service, B>;
type Future = H2ServiceResponse<T, S, B>; type Future = H2ServiceResponse<T, S, B>;
fn new_service(&self, cfg: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
H2ServiceResponse { H2ServiceResponse {
fut: self.srv.new_service(cfg), fut: self.srv.new_service(()),
cfg: Some(self.cfg.clone()), cfg: Some(self.cfg.clone()),
on_connect: self.on_connect.clone(), on_connect: self.on_connect.clone(),
_t: PhantomData, _t: PhantomData,

View File

@ -282,11 +282,11 @@ where
type Service = HttpServiceHandler<T, S::Service, B, X::Service, U::Service>; type Service = HttpServiceHandler<T, S::Service, B, X::Service, U::Service>;
type Future = HttpServiceResponse<T, S, B, X, U>; type Future = HttpServiceResponse<T, S, B, X, U>;
fn new_service(&self, cfg: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
HttpServiceResponse { HttpServiceResponse {
fut: self.srv.new_service(cfg), fut: self.srv.new_service(()),
fut_ex: Some(self.expect.new_service(cfg)), fut_ex: Some(self.expect.new_service(())),
fut_upg: self.upgrade.as_ref().map(|f| f.new_service(cfg)), fut_upg: self.upgrade.as_ref().map(|f| f.new_service(())),
expect: None, expect: None,
upgrade: None, upgrade: None,
on_connect: self.on_connect.clone(), on_connect: self.on_connect.clone(),

View File

@ -66,7 +66,7 @@ where
type Service = AppInitService<T::Service, B>; type Service = AppInitService<T::Service, B>;
type Future = AppInitResult<T, B>; type Future = AppInitResult<T, B>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
// update resource default service // update resource default service
let default = self.default.clone().unwrap_or_else(|| { let default = self.default.clone().unwrap_or_else(|| {
Rc::new(boxed::factory(service_fn(|req: ServiceRequest| { Rc::new(boxed::factory(service_fn(|req: ServiceRequest| {
@ -115,7 +115,7 @@ where
AppInitResult { AppInitResult {
endpoint: None, endpoint: None,
endpoint_fut: self.endpoint.new_service(&()), endpoint_fut: self.endpoint.new_service(()),
data: self.data.clone(), data: self.data.clone(),
data_factories: Vec::new(), data_factories: Vec::new(),
data_factories_fut: self.data_factories.iter().map(|f| f()).collect(), data_factories_fut: self.data_factories.iter().map(|f| f()).collect(),
@ -273,7 +273,7 @@ impl ServiceFactory for AppRoutingFactory {
type Service = AppRouting; type Service = AppRouting;
type Future = AppRoutingFactoryResponse; type Future = AppRoutingFactoryResponse;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
AppRoutingFactoryResponse { AppRoutingFactoryResponse {
fut: self fut: self
.services .services
@ -282,12 +282,12 @@ impl ServiceFactory for AppRoutingFactory {
CreateAppRoutingItem::Future( CreateAppRoutingItem::Future(
Some(path.clone()), Some(path.clone()),
guards.borrow_mut().take(), guards.borrow_mut().take(),
service.new_service(&()).boxed_local(), service.new_service(()).boxed_local(),
) )
}) })
.collect(), .collect(),
default: None, default: None,
default_fut: Some(self.default.new_service(&())), default_fut: Some(self.default.new_service(())),
} }
} }
} }
@ -432,8 +432,8 @@ impl ServiceFactory for AppEntry {
type Service = AppRouting; type Service = AppRouting;
type Future = AppRoutingFactoryResponse; type Future = AppRoutingFactoryResponse;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
self.factory.borrow_mut().as_mut().unwrap().new_service(&()) self.factory.borrow_mut().as_mut().unwrap().new_service(())
} }
} }

View File

@ -177,7 +177,7 @@ where
type Service = ExtractService<T, S>; type Service = ExtractService<T, S>;
type Future = Ready<Result<Self::Service, ()>>; type Future = Ready<Result<Self::Service, ()>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
ok(ExtractService { ok(ExtractService {
_t: PhantomData, _t: PhantomData,
service: self.service.clone(), service: self.service.clone(),

View File

@ -435,9 +435,9 @@ impl ServiceFactory for ResourceFactory {
type Service = ResourceService; type Service = ResourceService;
type Future = CreateResourceService; type Future = CreateResourceService;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
let default_fut = if let Some(ref default) = *self.default.borrow() { let default_fut = if let Some(ref default) = *self.default.borrow() {
Some(default.new_service(&())) Some(default.new_service(()))
} else { } else {
None None
}; };
@ -446,7 +446,7 @@ impl ServiceFactory for ResourceFactory {
fut: self fut: self
.routes .routes
.iter() .iter()
.map(|route| CreateRouteServiceItem::Future(route.new_service(&()))) .map(|route| CreateRouteServiceItem::Future(route.new_service(())))
.collect(), .collect(),
data: self.data.clone(), data: self.data.clone(),
default: None, default: None,
@ -575,8 +575,8 @@ impl ServiceFactory for ResourceEndpoint {
type Service = ResourceService; type Service = ResourceService;
type Future = CreateResourceService; type Future = CreateResourceService;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
self.factory.borrow_mut().as_mut().unwrap().new_service(&()) self.factory.borrow_mut().as_mut().unwrap().new_service(())
} }
} }

View File

@ -69,9 +69,9 @@ impl ServiceFactory for Route {
type Service = RouteService; type Service = RouteService;
type Future = CreateRouteService; type Future = CreateRouteService;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
CreateRouteService { CreateRouteService {
fut: self.service.new_service(&()), fut: self.service.new_service(()),
guards: self.guards.clone(), guards: self.guards.clone(),
} }
} }
@ -280,9 +280,9 @@ where
type Service = BoxedRouteService<ServiceRequest, Self::Response>; type Service = BoxedRouteService<ServiceRequest, Self::Response>;
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>; type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
self.service self.service
.new_service(&()) .new_service(())
.map(|result| match result { .map(|result| match result {
Ok(service) => { Ok(service) => {
let service: BoxedRouteService<_, _> = let service: BoxedRouteService<_, _> =

View File

@ -488,9 +488,9 @@ impl ServiceFactory for ScopeFactory {
type Service = ScopeService; type Service = ScopeService;
type Future = ScopeFactoryResponse; type Future = ScopeFactoryResponse;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
let default_fut = if let Some(ref default) = *self.default.borrow() { let default_fut = if let Some(ref default) = *self.default.borrow() {
Some(default.new_service(&())) Some(default.new_service(()))
} else { } else {
None None
}; };
@ -503,7 +503,7 @@ impl ServiceFactory for ScopeFactory {
CreateScopeServiceItem::Future( CreateScopeServiceItem::Future(
Some(path.clone()), Some(path.clone()),
guards.borrow_mut().take(), guards.borrow_mut().take(),
service.new_service(&()), service.new_service(()),
) )
}) })
.collect(), .collect(),
@ -656,8 +656,8 @@ impl ServiceFactory for ScopeEndpoint {
type Service = ScopeService; type Service = ScopeService;
type Future = ScopeFactoryResponse; type Future = ScopeFactoryResponse;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: ()) -> Self::Future {
self.factory.borrow_mut().as_mut().unwrap().new_service(&()) self.factory.borrow_mut().as_mut().unwrap().new_service(())
} }
} }

View File

@ -78,7 +78,7 @@ where
S::InitError: std::fmt::Debug, S::InitError: std::fmt::Debug,
{ {
let srv = app.into_factory(); let srv = app.into_factory();
srv.new_service(&()).await.unwrap() srv.new_service(()).await.unwrap()
} }
/// Calls service and waits for response future completion. /// Calls service and waits for response future completion.