Merge branch 'master' into master

This commit is contained in:
Haze 2019-04-03 18:42:52 -04:00 committed by GitHub
commit 932c07b1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -8,6 +8,10 @@
* Added `URLPath` option for logger
* Added `ServiceRequest::app_data()`, returns `Data<T>`
* Added `ServiceFromRequest::app_data()`, returns `Data<T>`
### Changed
* Move multipart support to actix-multipart crate

View File

@ -13,7 +13,7 @@ use actix_router::{Path, Resource, Url};
use futures::future::{ok, FutureResult, IntoFuture};
use crate::config::{AppConfig, ServiceConfig};
use crate::data::RouteData;
use crate::data::{Data, RouteData};
use crate::request::HttpRequest;
use crate::rmap::ResourceMap;
@ -173,6 +173,16 @@ impl<P> ServiceRequest<P> {
pub fn app_config(&self) -> &AppConfig {
self.req.config()
}
/// Get an application data stored with `App::data()` method during
/// application configuration.
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
if let Some(st) = self.req.config().extensions().get::<Data<T>>() {
Some(st.clone())
} else {
None
}
}
}
impl<P> Resource<Url> for ServiceRequest<P> {
@ -270,6 +280,16 @@ impl<P> ServiceFromRequest<P> {
ServiceResponse::new(self.req, err.into().into())
}
/// Get an application data stored with `App::data()` method during
/// application configuration.
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
if let Some(st) = self.req.config().extensions().get::<Data<T>>() {
Some(st.clone())
} else {
None
}
}
/// Load route data. Route data could be set during
/// route configuration with `Route::data()` method.
pub fn route_data<T: 'static>(&self) -> Option<&RouteData<T>> {