From 539e8c11ec4d256b0b21884f5330d71afcc076cc Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 27 Jun 2019 23:34:21 +0800 Subject: [PATCH] Cleanup len parse code --- src/types/json.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/types/json.rs b/src/types/json.rs index 92b865c05..de0ffb54c 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -322,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 {