diff --git a/CHANGES.md b/CHANGES.md index 0d40cf31..3cc6e5ef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,10 @@ * Added helper functions for reading test response body, `test::read_response()` and test::read_response_json()` +### Changed + +* Rename `RouterConfig` to `ServiceConfig` + ### Fixed * Fixed `TestRequest::app_data()` diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 89eead56..4923536f 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -10,7 +10,7 @@ use std::{cmp, io}; use actix_service::boxed::{self, BoxedNewService, BoxedService}; use actix_service::{IntoNewService, NewService, Service}; use actix_web::dev::{ - HttpServiceFactory, Payload, ResourceDef, ServiceConfig, ServiceRequest, + AppService, HttpServiceFactory, Payload, ResourceDef, ServiceRequest, ServiceResponse, }; use actix_web::error::{BlockingError, Error, ErrorInternalServerError}; @@ -349,7 +349,7 @@ impl Files { } impl HttpServiceFactory for Files { - fn register(self, config: &mut ServiceConfig) { + fn register(self, config: &mut AppService) { if self.default.borrow().is_none() { *self.default.borrow_mut() = Some(config.default_service()); } diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index 348ce86a..1a5f7929 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -62,7 +62,7 @@ impl fmt::Display for Args { pub struct {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} let resource = actix_web::Resource::new(\"{path}\"){guards}.{to}({name}); diff --git a/src/app.rs b/src/app.rs index 6c34123d..bf6f2580 100644 --- a/src/app.rs +++ b/src/app.rs @@ -12,7 +12,7 @@ use actix_service::{ use futures::IntoFuture; 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::dev::ResourceDef; use crate::error::Error; @@ -125,7 +125,7 @@ where /// use actix_web::{web, middleware, App, HttpResponse}; /// /// // 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") /// .route(web::get().to(|| HttpResponse::Ok())) /// .route(web::head().to(|| HttpResponse::MethodNotAllowed())) @@ -141,9 +141,9 @@ where /// ``` pub fn configure(mut self, f: F) -> Self where - F: Fn(&mut RouterConfig), + F: Fn(&mut ServiceConfig), { - let mut cfg = RouterConfig::new(); + let mut cfg = ServiceConfig::new(); f(&mut cfg); self.data.extend(cfg.data); self.services.extend(cfg.services); diff --git a/src/app_service.rs b/src/app_service.rs index a5d90636..63bf84e7 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -10,7 +10,7 @@ use actix_service::{fn_service, NewService, Service}; use futures::future::{ok, Either, FutureResult}; use futures::{Async, Future, Poll}; -use crate::config::{AppConfig, ServiceConfig}; +use crate::config::{AppConfig, AppService}; use crate::data::{DataFactory, DataFactoryResult}; use crate::error::Error; use crate::guard::Guard; @@ -77,8 +77,7 @@ where loc_cfg.addr = cfg.local_addr(); } - let mut config = - ServiceConfig::new(self.config.borrow().clone(), default.clone()); + let mut config = AppService::new(self.config.borrow().clone(), default.clone()); // register services std::mem::replace(&mut *self.services.borrow_mut(), Vec::new()) diff --git a/src/config.rs b/src/config.rs index c28b6678..07bfebcf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,7 +23,7 @@ type HttpNewService = boxed::BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>; /// Application configuration -pub struct ServiceConfig { +pub struct AppService { config: AppConfig, root: bool, default: Rc, @@ -35,10 +35,10 @@ pub struct ServiceConfig { )>, } -impl ServiceConfig { +impl AppService { /// Crate server settings instance pub(crate) fn new(config: AppConfig, default: Rc) -> Self { - ServiceConfig { + AppService { config, default, root: true, @@ -63,7 +63,7 @@ impl ServiceConfig { } pub(crate) fn clone_config(&self) -> Self { - ServiceConfig { + AppService { config: self.config.clone(), default: self.default.clone(), 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 /// to set of external methods. This could help with /// modularization of big application configuration. -pub struct RouterConfig { +pub struct ServiceConfig { pub(crate) services: Vec>, pub(crate) data: Vec>, pub(crate) external: Vec, } -impl RouterConfig { +impl ServiceConfig { pub(crate) fn new() -> Self { Self { services: Vec::new(), @@ -261,7 +261,7 @@ mod tests { #[test] fn test_data() { - let cfg = |cfg: &mut RouterConfig| { + let cfg = |cfg: &mut ServiceConfig| { cfg.data(10usize); }; @@ -276,7 +276,7 @@ mod tests { #[test] fn test_data_factory() { - let cfg = |cfg: &mut RouterConfig| { + let cfg = |cfg: &mut ServiceConfig| { cfg.data_factory(|| Ok::<_, ()>(10usize)); }; @@ -288,7 +288,7 @@ mod tests { let resp = block_on(srv.call(req)).unwrap(); assert_eq!(resp.status(), StatusCode::OK); - let cfg2 = |cfg: &mut RouterConfig| { + let cfg2 = |cfg: &mut ServiceConfig| { cfg.data_factory(|| Ok::<_, ()>(10u32)); }; let mut srv = init_service( diff --git a/src/lib.rs b/src/lib.rs index 6636d96d..6abf37c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,7 +133,7 @@ pub mod 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::rmap::ResourceMap; pub use crate::service::{HttpServiceFactory, ServiceRequest, ServiceResponse}; diff --git a/src/resource.rs b/src/resource.rs index a8268302..15abcada 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -10,7 +10,7 @@ use actix_service::{ use futures::future::{ok, Either, FutureResult}; 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::guard::Guard; use crate::handler::{AsyncFactory, Factory}; @@ -347,7 +347,7 @@ where InitError = (), > + 'static, { - fn register(mut self, config: &mut ServiceConfig) { + fn register(mut self, config: &mut AppService) { let guards = if self.guards.is_empty() { None } else { diff --git a/src/scope.rs b/src/scope.rs index 5678158e..0ac73a2e 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -11,7 +11,7 @@ use actix_service::{ use futures::future::{ok, Either, Future, FutureResult}; use futures::{Async, IntoFuture, Poll}; -use crate::dev::{HttpServiceFactory, ServiceConfig}; +use crate::dev::{AppService, HttpServiceFactory}; use crate::error::Error; use crate::guard::Guard; use crate::resource::Resource; @@ -303,7 +303,7 @@ where InitError = (), > + 'static, { - fn register(self, config: &mut ServiceConfig) { + fn register(self, config: &mut AppService) { // update default resource if needed if self.default.borrow().is_none() { *self.default.borrow_mut() = Some(config.default_service()); diff --git a/src/service.rs b/src/service.rs index e5b0896e..8bc2ff9a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -10,16 +10,16 @@ use actix_http::{ use actix_router::{Path, Resource, Url}; use futures::future::{ok, FutureResult, IntoFuture}; -use crate::config::{AppConfig, ServiceConfig}; +use crate::config::{AppConfig, AppService}; use crate::data::Data; use crate::request::HttpRequest; pub trait HttpServiceFactory { - fn register(self, config: &mut ServiceConfig); + fn register(self, config: &mut AppService); } pub(crate) trait ServiceFactory { - fn register(&mut self, config: &mut ServiceConfig); + fn register(&mut self, config: &mut AppService); } pub(crate) struct ServiceFactoryWrapper { @@ -38,7 +38,7 @@ impl ServiceFactory for ServiceFactoryWrapper where T: HttpServiceFactory, { - fn register(&mut self, config: &mut ServiceConfig) { + fn register(&mut self, config: &mut AppService) { if let Some(item) = self.factory.take() { item.register(config) } diff --git a/src/web.rs b/src/web.rs index ece869b2..079dec51 100644 --- a/src/web.rs +++ b/src/web.rs @@ -13,7 +13,7 @@ use crate::responder::Responder; use crate::route::Route; use crate::scope::Scope; -pub use crate::config::RouterConfig; +pub use crate::config::ServiceConfig; pub use crate::data::{Data, RouteData}; pub use crate::request::HttpRequest; pub use crate::types::*;