diff --git a/CHANGES.md b/CHANGES.md index 0b3f3e0c..11158925 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,10 +6,14 @@ * Add `Responder` impl for `(T, StatusCode) where T: Responder` +* Allow to access app's resource map via + `ServiceRequest::resource_map()` and `HttpRequest::resource_map()` methods. + ### Changed * Upgrade `rand` dependency version to 0.7 + ## [1.0.3] - 2019-06-28 ### Added diff --git a/src/request.rs b/src/request.rs index d0d24f4f..0fc0647f 100644 --- a/src/request.rs +++ b/src/request.rs @@ -174,6 +174,12 @@ impl HttpRequest { self.url_for(name, &NO_PARAMS) } + #[inline] + /// Get a reference to a `ResourceMap` of current application. + pub fn resource_map(&self) -> &ResourceMap { + &self.0.rmap + } + /// Peer socket address /// /// Peer address is actual socket address, if proxy is used in front of diff --git a/src/service.rs b/src/service.rs index 722813a9..5863a100 100644 --- a/src/service.rs +++ b/src/service.rs @@ -18,6 +18,7 @@ use crate::dev::insert_slash; use crate::guard::Guard; use crate::info::ConnectionInfo; use crate::request::HttpRequest; +use crate::rmap::ResourceMap; pub trait HttpServiceFactory { fn register(self, config: &mut AppService); @@ -169,10 +170,17 @@ impl ServiceRequest { } #[inline] + /// Get a mutable reference to the Path parameters. pub fn match_info_mut(&mut self) -> &mut Path { self.0.match_info_mut() } + #[inline] + /// Get a reference to a `ResourceMap` of current application. + pub fn resource_map(&self) -> &ResourceMap { + self.0.resource_map() + } + /// Service configuration #[inline] pub fn app_config(&self) -> &AppConfig {