From a01db994f6af8344669642dae99d58ca1b072189 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 2 Jun 2018 08:28:33 -0700 Subject: [PATCH] multi extractor for json --- json/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/json/src/main.rs b/json/src/main.rs index 5f320370..0e313152 100644 --- a/json/src/main.rs +++ b/json/src/main.rs @@ -41,6 +41,12 @@ fn extract_item(item: Json) -> HttpResponse { HttpResponse::Ok().json(item.0) // <- send response } +/// This handler uses json extractor with limit +fn extract_item_limit((item, _req): (Json, HttpRequest)) -> HttpResponse { + println!("model: {:?}", &item); + HttpResponse::Ok().json(item.0) // <- send response +} + const MAX_SIZE: usize = 262_144; // max payload size is 256k /// This handler manually load request payload and parse json object @@ -104,6 +110,11 @@ fn main() { .with(extract_item) .limit(4096); // <- limit size of the payload }) + .resource("/extractor2", |r| { + r.method(http::Method::POST) + .with(extract_item_limit) + .0.limit(4096); // <- limit size of the payload + }) .resource("/manual", |r| r.method(http::Method::POST).f(index_manual)) .resource("/mjsonrust", |r| r.method(http::Method::POST).f(index_mjsonrust)) .resource("/", |r| r.method(http::Method::POST).f(index))