1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-09-01 01:16:59 +02:00

unify route and app data, it allows to provide global extractor config #775

This commit is contained in:
Nikolay Kim
2019-05-04 19:43:49 -07:00
parent 01cfcf3b75
commit fa78da8156
18 changed files with 292 additions and 426 deletions

View File

@@ -130,7 +130,7 @@ impl FromRequest for Bytes {
#[inline]
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
let mut tmp;
let cfg = if let Some(cfg) = req.route_data::<PayloadConfig>() {
let cfg = if let Some(cfg) = req.app_data::<PayloadConfig>() {
cfg
} else {
tmp = PayloadConfig::default();
@@ -167,12 +167,11 @@ impl FromRequest for Bytes {
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/index.html").route(
/// web::get()
/// .data(String::configure(|cfg| { // <- limit size of the payload
/// cfg.limit(4096)
/// }))
/// .to(index)) // <- register handler with extractor params
/// web::resource("/index.html")
/// .data(String::configure(|cfg| { // <- limit size of the payload
/// cfg.limit(4096)
/// }))
/// .route(web::get().to(index)) // <- register handler with extractor params
/// );
/// }
/// ```
@@ -185,7 +184,7 @@ impl FromRequest for String {
#[inline]
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
let mut tmp;
let cfg = if let Some(cfg) = req.route_data::<PayloadConfig>() {
let cfg = if let Some(cfg) = req.app_data::<PayloadConfig>() {
cfg
} else {
tmp = PayloadConfig::default();