diff --git a/src/extract/form.rs b/src/extract/form.rs index 19849ac8..6b13c5f8 100644 --- a/src/extract/form.rs +++ b/src/extract/form.rs @@ -130,7 +130,7 @@ impl fmt::Display for Form { /// web::resource("/index.html") /// .route(web::get() /// // change `Form` extractor configuration -/// .config(web::FormConfig::default().limit(4097)) +/// .data(web::FormConfig::default().limit(4097)) /// .to(index)) /// ); /// } diff --git a/src/extract/json.rs b/src/extract/json.rs index f74b082d..3847e71a 100644 --- a/src/extract/json.rs +++ b/src/extract/json.rs @@ -215,7 +215,7 @@ where /// fn main() { /// let app = App::new().service( /// web::resource("/index.html").route( -/// web::post().config( +/// web::post().data( /// // change json extractor configuration /// web::JsonConfig::default().limit(4096) /// .error_handler(|err, req| { // <- create custom error response diff --git a/src/extract/mod.rs b/src/extract/mod.rs index 25a046d4..738f8918 100644 --- a/src/extract/mod.rs +++ b/src/extract/mod.rs @@ -262,7 +262,7 @@ mod tests { header::CONTENT_TYPE, "application/x-www-form-urlencoded", ) - .config(FormConfig::default().limit(4096)) + .route_data(FormConfig::default().limit(4096)) .to_from(); let r = block_on(Option::>::from_request(&mut req)).unwrap(); diff --git a/src/extract/payload.rs b/src/extract/payload.rs index 13532eee..3fc0c964 100644 --- a/src/extract/payload.rs +++ b/src/extract/payload.rs @@ -177,7 +177,7 @@ where /// let app = App::new().service( /// web::resource("/index.html").route( /// web::get() -/// .config(web::PayloadConfig::new(4096)) // <- limit size of the payload +/// .data(web::PayloadConfig::new(4096)) // <- limit size of the payload /// .to(index)) // <- register handler with extractor params /// ); /// } diff --git a/src/route.rs b/src/route.rs index 5d339a3b..30905d40 100644 --- a/src/route.rs +++ b/src/route.rs @@ -40,28 +40,28 @@ type BoxedRouteNewService = Box< pub struct Route

{ service: BoxedRouteNewService, ServiceResponse>, guards: Rc>>, - config: Option, - config_ref: Rc>>>, + data: Option, + data_ref: Rc>>>, } impl Route

{ /// Create new route which matches any request. pub fn new() -> Route

{ - let config_ref = Rc::new(RefCell::new(None)); + let data_ref = Rc::new(RefCell::new(None)); Route { service: Box::new(RouteNewService::new( - Extract::new(config_ref.clone()).and_then( + Extract::new(data_ref.clone()).and_then( Handler::new(HttpResponse::NotFound).map_err(|_| panic!()), ), )), guards: Rc::new(Vec::new()), - config: None, - config_ref, + data: None, + data_ref, } } pub(crate) fn finish(mut self) -> Self { - *self.config_ref.borrow_mut() = self.config.take().map(|e| Rc::new(e)); + *self.data_ref.borrow_mut() = self.data.take().map(|e| Rc::new(e)); self } @@ -180,24 +180,6 @@ impl Route

{ self } - // pub fn map>( - // self, - // md: F, - // ) -> RouteServiceBuilder - // where - // T: NewService< - // Request = HandlerRequest, - // Response = HandlerRequest, - // InitError = Error, - // >, - // { - // RouteServiceBuilder { - // service: md.into_new_service(), - // guards: self.guards, - // _t: PhantomData, - // } - // } - /// Set handler function, use request extractors for parameters. /// /// ```rust @@ -253,7 +235,7 @@ impl Route

{ R: Responder + 'static, { self.service = Box::new(RouteNewService::new( - Extract::new(self.config_ref.clone()) + Extract::new(self.data_ref.clone()) .and_then(Handler::new(handler).map_err(|_| panic!())), )); self @@ -295,14 +277,14 @@ impl Route

{ R::Error: Into, { self.service = Box::new(RouteNewService::new( - Extract::new(self.config_ref.clone()) + Extract::new(self.data_ref.clone()) .and_then(AsyncHandler::new(handler).map_err(|_| panic!())), )); self } - /// This method allows to add extractor configuration - /// for specific route. + /// Provide route specific data. This method allows to add extractor + /// configuration or specific state available via `RouteData` extractor. /// /// ```rust /// use actix_web::{web, App}; @@ -317,17 +299,17 @@ impl Route

{ /// web::resource("/index.html").route( /// web::get() /// // limit size of the payload - /// .config(web::PayloadConfig::new(4096)) + /// .data(web::PayloadConfig::new(4096)) /// // register handler /// .to(index) /// )); /// } /// ``` - pub fn config(mut self, config: C) -> Self { - if self.config.is_none() { - self.config = Some(Extensions::new()); + pub fn data(mut self, data: C) -> Self { + if self.data.is_none() { + self.data = Some(Extensions::new()); } - self.config.as_mut().unwrap().insert(config); + self.data.as_mut().unwrap().insert(data); self } } diff --git a/src/test.rs b/src/test.rs index 57a6d396..4db268f1 100644 --- a/src/test.rs +++ b/src/test.rs @@ -265,8 +265,8 @@ impl TestRequest { self } - /// Set request config - pub fn config(self, data: T) -> Self { + /// Set route data + pub fn route_data(self, data: T) -> Self { self.config.extensions.borrow_mut().insert(data); self }