mirror of https://github.com/fafhrd91/actix-web
fix
This commit is contained in:
parent
812269d656
commit
6cb1e32431
25
src/scope.rs
25
src/scope.rs
|
@ -424,7 +424,6 @@ where
|
||||||
|
|
||||||
// complete scope pipeline creation
|
// complete scope pipeline creation
|
||||||
*self.factory_ref.borrow_mut() = Some(ScopeFactory {
|
*self.factory_ref.borrow_mut() = Some(ScopeFactory {
|
||||||
app_data: self.app_data.take().map(Rc::new),
|
|
||||||
default,
|
default,
|
||||||
services: cfg
|
services: cfg
|
||||||
.into_services()
|
.into_services()
|
||||||
|
@ -446,18 +445,25 @@ where
|
||||||
Some(self.guards)
|
Some(self.guards)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let app_data = self.app_data.take().map(Rc::new);
|
||||||
|
let endpoint = apply_fn_factory(self.endpoint, move |mut req: ServiceRequest, srv| {
|
||||||
|
if let Some(ref data) = app_data {
|
||||||
|
req.add_data_container(Rc::clone(data));
|
||||||
|
}
|
||||||
|
srv.call(req)
|
||||||
|
});
|
||||||
|
|
||||||
// register final service
|
// register final service
|
||||||
config.register_service(
|
config.register_service(
|
||||||
ResourceDef::root_prefix(&self.rdef),
|
ResourceDef::root_prefix(&self.rdef),
|
||||||
guards,
|
guards,
|
||||||
self.endpoint,
|
endpoint,
|
||||||
Some(Rc::new(rmap)),
|
Some(Rc::new(rmap)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ScopeFactory {
|
pub struct ScopeFactory {
|
||||||
app_data: Option<Rc<Extensions>>,
|
|
||||||
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>,
|
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>,
|
||||||
default: Rc<HttpNewService>,
|
default: Rc<HttpNewService>,
|
||||||
}
|
}
|
||||||
|
@ -485,8 +491,6 @@ impl ServiceFactory<ServiceRequest> for ScopeFactory {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let app_data = self.app_data.clone();
|
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let default = default_fut.await?;
|
let default = default_fut.await?;
|
||||||
|
|
||||||
|
@ -502,17 +506,12 @@ impl ServiceFactory<ServiceRequest> for ScopeFactory {
|
||||||
})
|
})
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
Ok(ScopeService {
|
Ok(ScopeService { router, default })
|
||||||
app_data,
|
|
||||||
router,
|
|
||||||
default,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ScopeService {
|
pub struct ScopeService {
|
||||||
app_data: Option<Rc<Extensions>>,
|
|
||||||
router: Router<HttpService, Vec<Box<dyn Guard>>>,
|
router: Router<HttpService, Vec<Box<dyn Guard>>>,
|
||||||
default: HttpService,
|
default: HttpService,
|
||||||
}
|
}
|
||||||
|
@ -536,10 +535,6 @@ impl Service<ServiceRequest> for ScopeService {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(ref app_data) = self.app_data {
|
|
||||||
req.add_data_container(app_data.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((srv, _info)) = res {
|
if let Some((srv, _info)) = res {
|
||||||
srv.call(req)
|
srv.call(req)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue