1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

Call req.path() on Json extractor error only (#945)

* Call req.path() on Json extractor error only

* Cleanup len parse code
This commit is contained in:
messense 2019-06-28 12:44:53 +08:00 committed by Nikolay Kim
parent af9fb5d190
commit 44bb79cd07

View File

@ -180,16 +180,14 @@ where
.map(|c| (c.limit, c.ehandler.clone(), c.content_type.clone())) .map(|c| (c.limit, c.ehandler.clone(), c.content_type.clone()))
.unwrap_or((32768, None, None)); .unwrap_or((32768, None, None));
let path = req.path().to_string();
Box::new( Box::new(
JsonBody::new(req, payload, ctype) JsonBody::new(req, payload, ctype)
.limit(limit) .limit(limit)
.map_err(move |e| { .map_err(move |e| {
log::debug!( log::debug!(
"Failed to deserialize Json from payload. \ "Failed to deserialize Json from payload. \
Request path: {:?}", Request path: {}",
path req2.path()
); );
if let Some(err) = err { if let Some(err) = err {
(*err)(e, &req2) (*err)(e, &req2)
@ -324,14 +322,11 @@ where
}; };
} }
let mut len = None; let len = req
if let Some(l) = req.headers().get(&CONTENT_LENGTH) { .headers()
if let Ok(s) = l.to_str() { .get(&CONTENT_LENGTH)
if let Ok(l) = s.parse::<usize>() { .and_then(|l| l.to_str().ok())
len = Some(l) .and_then(|s| s.parse::<usize>().ok());
}
}
}
let payload = Decompress::from_headers(payload.take(), req.headers()); let payload = Decompress::from_headers(payload.take(), req.headers());
JsonBody { JsonBody {