1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 18:44:35 +01:00

Rename RouterConfig to ServiceConfig

This commit is contained in:
Nikolay Kim 2019-04-15 07:32:49 -07:00
parent 1eebd47072
commit 09cdf1e302
11 changed files with 33 additions and 30 deletions

View File

@ -7,6 +7,10 @@
* Added helper functions for reading test response body, * Added helper functions for reading test response body,
`test::read_response()` and test::read_response_json()` `test::read_response()` and test::read_response_json()`
### Changed
* Rename `RouterConfig` to `ServiceConfig`
### Fixed ### Fixed
* Fixed `TestRequest::app_data()` * Fixed `TestRequest::app_data()`

View File

@ -10,7 +10,7 @@ use std::{cmp, io};
use actix_service::boxed::{self, BoxedNewService, BoxedService}; use actix_service::boxed::{self, BoxedNewService, BoxedService};
use actix_service::{IntoNewService, NewService, Service}; use actix_service::{IntoNewService, NewService, Service};
use actix_web::dev::{ use actix_web::dev::{
HttpServiceFactory, Payload, ResourceDef, ServiceConfig, ServiceRequest, AppService, HttpServiceFactory, Payload, ResourceDef, ServiceRequest,
ServiceResponse, ServiceResponse,
}; };
use actix_web::error::{BlockingError, Error, ErrorInternalServerError}; use actix_web::error::{BlockingError, Error, ErrorInternalServerError};
@ -349,7 +349,7 @@ impl Files {
} }
impl HttpServiceFactory for Files { impl HttpServiceFactory for Files {
fn register(self, config: &mut ServiceConfig) { fn register(self, config: &mut AppService) {
if self.default.borrow().is_none() { if self.default.borrow().is_none() {
*self.default.borrow_mut() = Some(config.default_service()); *self.default.borrow_mut() = Some(config.default_service());
} }

View File

@ -62,7 +62,7 @@ impl fmt::Display for Args {
pub struct {name}; pub struct {name};
impl actix_web::dev::HttpServiceFactory for {name} {{ impl actix_web::dev::HttpServiceFactory for {name} {{
fn register(self, config: &mut actix_web::dev::ServiceConfig) {{ fn register(self, config: &mut actix_web::dev::AppService) {{
{ast} {ast}
let resource = actix_web::Resource::new(\"{path}\"){guards}.{to}({name}); let resource = actix_web::Resource::new(\"{path}\"){guards}.{to}({name});

View File

@ -12,7 +12,7 @@ use actix_service::{
use futures::IntoFuture; use futures::IntoFuture;
use crate::app_service::{AppEntry, AppInit, AppRoutingFactory}; use crate::app_service::{AppEntry, AppInit, AppRoutingFactory};
use crate::config::{AppConfig, AppConfigInner, RouterConfig}; use crate::config::{AppConfig, AppConfigInner, ServiceConfig};
use crate::data::{Data, DataFactory}; use crate::data::{Data, DataFactory};
use crate::dev::ResourceDef; use crate::dev::ResourceDef;
use crate::error::Error; use crate::error::Error;
@ -125,7 +125,7 @@ where
/// use actix_web::{web, middleware, App, HttpResponse}; /// use actix_web::{web, middleware, App, HttpResponse};
/// ///
/// // this function could be located in different module /// // this function could be located in different module
/// fn config(cfg: &mut web::RouterConfig) { /// fn config(cfg: &mut web::ServiceConfig) {
/// cfg.service(web::resource("/test") /// cfg.service(web::resource("/test")
/// .route(web::get().to(|| HttpResponse::Ok())) /// .route(web::get().to(|| HttpResponse::Ok()))
/// .route(web::head().to(|| HttpResponse::MethodNotAllowed())) /// .route(web::head().to(|| HttpResponse::MethodNotAllowed()))
@ -141,9 +141,9 @@ where
/// ``` /// ```
pub fn configure<F>(mut self, f: F) -> Self pub fn configure<F>(mut self, f: F) -> Self
where where
F: Fn(&mut RouterConfig), F: Fn(&mut ServiceConfig),
{ {
let mut cfg = RouterConfig::new(); let mut cfg = ServiceConfig::new();
f(&mut cfg); f(&mut cfg);
self.data.extend(cfg.data); self.data.extend(cfg.data);
self.services.extend(cfg.services); self.services.extend(cfg.services);

View File

@ -10,7 +10,7 @@ use actix_service::{fn_service, NewService, Service};
use futures::future::{ok, Either, FutureResult}; use futures::future::{ok, Either, FutureResult};
use futures::{Async, Future, Poll}; use futures::{Async, Future, Poll};
use crate::config::{AppConfig, ServiceConfig}; use crate::config::{AppConfig, AppService};
use crate::data::{DataFactory, DataFactoryResult}; use crate::data::{DataFactory, DataFactoryResult};
use crate::error::Error; use crate::error::Error;
use crate::guard::Guard; use crate::guard::Guard;
@ -77,8 +77,7 @@ where
loc_cfg.addr = cfg.local_addr(); loc_cfg.addr = cfg.local_addr();
} }
let mut config = let mut config = AppService::new(self.config.borrow().clone(), default.clone());
ServiceConfig::new(self.config.borrow().clone(), default.clone());
// register services // register services
std::mem::replace(&mut *self.services.borrow_mut(), Vec::new()) std::mem::replace(&mut *self.services.borrow_mut(), Vec::new())

View File

@ -23,7 +23,7 @@ type HttpNewService =
boxed::BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>; boxed::BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
/// Application configuration /// Application configuration
pub struct ServiceConfig { pub struct AppService {
config: AppConfig, config: AppConfig,
root: bool, root: bool,
default: Rc<HttpNewService>, default: Rc<HttpNewService>,
@ -35,10 +35,10 @@ pub struct ServiceConfig {
)>, )>,
} }
impl ServiceConfig { impl AppService {
/// Crate server settings instance /// Crate server settings instance
pub(crate) fn new(config: AppConfig, default: Rc<HttpNewService>) -> Self { pub(crate) fn new(config: AppConfig, default: Rc<HttpNewService>) -> Self {
ServiceConfig { AppService {
config, config,
default, default,
root: true, root: true,
@ -63,7 +63,7 @@ impl ServiceConfig {
} }
pub(crate) fn clone_config(&self) -> Self { pub(crate) fn clone_config(&self) -> Self {
ServiceConfig { AppService {
config: self.config.clone(), config: self.config.clone(),
default: self.default.clone(), default: self.default.clone(),
services: Vec::new(), services: Vec::new(),
@ -165,17 +165,17 @@ impl Default for AppConfigInner {
} }
} }
/// Router config. It is used for external configuration. /// Service config is used for external configuration.
/// Part of application configuration could be offloaded /// Part of application configuration could be offloaded
/// to set of external methods. This could help with /// to set of external methods. This could help with
/// modularization of big application configuration. /// modularization of big application configuration.
pub struct RouterConfig { pub struct ServiceConfig {
pub(crate) services: Vec<Box<ServiceFactory>>, pub(crate) services: Vec<Box<ServiceFactory>>,
pub(crate) data: Vec<Box<DataFactory>>, pub(crate) data: Vec<Box<DataFactory>>,
pub(crate) external: Vec<ResourceDef>, pub(crate) external: Vec<ResourceDef>,
} }
impl RouterConfig { impl ServiceConfig {
pub(crate) fn new() -> Self { pub(crate) fn new() -> Self {
Self { Self {
services: Vec::new(), services: Vec::new(),
@ -261,7 +261,7 @@ mod tests {
#[test] #[test]
fn test_data() { fn test_data() {
let cfg = |cfg: &mut RouterConfig| { let cfg = |cfg: &mut ServiceConfig| {
cfg.data(10usize); cfg.data(10usize);
}; };
@ -276,7 +276,7 @@ mod tests {
#[test] #[test]
fn test_data_factory() { fn test_data_factory() {
let cfg = |cfg: &mut RouterConfig| { let cfg = |cfg: &mut ServiceConfig| {
cfg.data_factory(|| Ok::<_, ()>(10usize)); cfg.data_factory(|| Ok::<_, ()>(10usize));
}; };
@ -288,7 +288,7 @@ mod tests {
let resp = block_on(srv.call(req)).unwrap(); let resp = block_on(srv.call(req)).unwrap();
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
let cfg2 = |cfg: &mut RouterConfig| { let cfg2 = |cfg: &mut ServiceConfig| {
cfg.data_factory(|| Ok::<_, ()>(10u32)); cfg.data_factory(|| Ok::<_, ()>(10u32));
}; };
let mut srv = init_service( let mut srv = init_service(

View File

@ -133,7 +133,7 @@ pub mod dev {
//! use actix_web::dev::*; //! use actix_web::dev::*;
//! ``` //! ```
pub use crate::config::{AppConfig, ServiceConfig}; pub use crate::config::{AppConfig, AppService};
pub use crate::info::ConnectionInfo; pub use crate::info::ConnectionInfo;
pub use crate::rmap::ResourceMap; pub use crate::rmap::ResourceMap;
pub use crate::service::{HttpServiceFactory, ServiceRequest, ServiceResponse}; pub use crate::service::{HttpServiceFactory, ServiceRequest, ServiceResponse};

View File

@ -10,7 +10,7 @@ use actix_service::{
use futures::future::{ok, Either, FutureResult}; use futures::future::{ok, Either, FutureResult};
use futures::{Async, Future, IntoFuture, Poll}; use futures::{Async, Future, IntoFuture, Poll};
use crate::dev::{insert_slash, HttpServiceFactory, ResourceDef, ServiceConfig}; use crate::dev::{insert_slash, AppService, HttpServiceFactory, ResourceDef};
use crate::extract::FromRequest; use crate::extract::FromRequest;
use crate::guard::Guard; use crate::guard::Guard;
use crate::handler::{AsyncFactory, Factory}; use crate::handler::{AsyncFactory, Factory};
@ -347,7 +347,7 @@ where
InitError = (), InitError = (),
> + 'static, > + 'static,
{ {
fn register(mut self, config: &mut ServiceConfig) { fn register(mut self, config: &mut AppService) {
let guards = if self.guards.is_empty() { let guards = if self.guards.is_empty() {
None None
} else { } else {

View File

@ -11,7 +11,7 @@ use actix_service::{
use futures::future::{ok, Either, Future, FutureResult}; use futures::future::{ok, Either, Future, FutureResult};
use futures::{Async, IntoFuture, Poll}; use futures::{Async, IntoFuture, Poll};
use crate::dev::{HttpServiceFactory, ServiceConfig}; use crate::dev::{AppService, HttpServiceFactory};
use crate::error::Error; use crate::error::Error;
use crate::guard::Guard; use crate::guard::Guard;
use crate::resource::Resource; use crate::resource::Resource;
@ -303,7 +303,7 @@ where
InitError = (), InitError = (),
> + 'static, > + 'static,
{ {
fn register(self, config: &mut ServiceConfig) { fn register(self, config: &mut AppService) {
// update default resource if needed // update default resource if needed
if self.default.borrow().is_none() { if self.default.borrow().is_none() {
*self.default.borrow_mut() = Some(config.default_service()); *self.default.borrow_mut() = Some(config.default_service());

View File

@ -10,16 +10,16 @@ use actix_http::{
use actix_router::{Path, Resource, Url}; use actix_router::{Path, Resource, Url};
use futures::future::{ok, FutureResult, IntoFuture}; use futures::future::{ok, FutureResult, IntoFuture};
use crate::config::{AppConfig, ServiceConfig}; use crate::config::{AppConfig, AppService};
use crate::data::Data; use crate::data::Data;
use crate::request::HttpRequest; use crate::request::HttpRequest;
pub trait HttpServiceFactory { pub trait HttpServiceFactory {
fn register(self, config: &mut ServiceConfig); fn register(self, config: &mut AppService);
} }
pub(crate) trait ServiceFactory { pub(crate) trait ServiceFactory {
fn register(&mut self, config: &mut ServiceConfig); fn register(&mut self, config: &mut AppService);
} }
pub(crate) struct ServiceFactoryWrapper<T> { pub(crate) struct ServiceFactoryWrapper<T> {
@ -38,7 +38,7 @@ impl<T> ServiceFactory for ServiceFactoryWrapper<T>
where where
T: HttpServiceFactory, T: HttpServiceFactory,
{ {
fn register(&mut self, config: &mut ServiceConfig) { fn register(&mut self, config: &mut AppService) {
if let Some(item) = self.factory.take() { if let Some(item) = self.factory.take() {
item.register(config) item.register(config)
} }

View File

@ -13,7 +13,7 @@ use crate::responder::Responder;
use crate::route::Route; use crate::route::Route;
use crate::scope::Scope; use crate::scope::Scope;
pub use crate::config::RouterConfig; pub use crate::config::ServiceConfig;
pub use crate::data::{Data, RouteData}; pub use crate::data::{Data, RouteData};
pub use crate::request::HttpRequest; pub use crate::request::HttpRequest;
pub use crate::types::*; pub use crate::types::*;