From 44bb79cd07af726c23825fd19a0f028ba3fd3a80 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 28 Jun 2019 12:44:53 +0800 Subject: [PATCH] Call req.path() on Json extractor error only (#945) * Call req.path() on Json extractor error only * Cleanup len parse code --- src/types/json.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/types/json.rs b/src/types/json.rs index 0789fb612..de0ffb54c 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -180,16 +180,14 @@ where .map(|c| (c.limit, c.ehandler.clone(), c.content_type.clone())) .unwrap_or((32768, None, None)); - let path = req.path().to_string(); - Box::new( JsonBody::new(req, payload, ctype) .limit(limit) .map_err(move |e| { log::debug!( "Failed to deserialize Json from payload. \ - Request path: {:?}", - path + Request path: {}", + req2.path() ); if let Some(err) = err { (*err)(e, &req2) @@ -324,14 +322,11 @@ where }; } - let mut len = None; - if let Some(l) = req.headers().get(&CONTENT_LENGTH) { - if let Ok(s) = l.to_str() { - if let Ok(l) = s.parse::() { - len = Some(l) - } - } - } + let len = req + .headers() + .get(&CONTENT_LENGTH) + .and_then(|l| l.to_str().ok()) + .and_then(|s| s.parse::().ok()); let payload = Decompress::from_headers(payload.take(), req.headers()); JsonBody {