From 925250370a2b2851edc1eb2b77f4a3ca0b46e358 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 19 Nov 2023 11:07:53 +0000 Subject: [PATCH] clarify comments for invalid json mime type --- actix-web/src/types/json.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/actix-web/src/types/json.rs b/actix-web/src/types/json.rs index 8813fa050..6b75c0cfe 100644 --- a/actix-web/src/types/json.rs +++ b/actix-web/src/types/json.rs @@ -334,11 +334,13 @@ impl JsonBody { || mime.suffix() == Some(mime::JSON) || ctype_fn.map_or(false, |predicate| predicate(mime)) } - (_, _) => { - // if `ctype_required` is false, assume payload is - // json even when content-type header is missing - !ctype_required - } + + // if content-type is expected but not parsable as mime type, bail + (true, _) => false, + + // if content-type validation is disabled, assume payload is JSON + // even when content-type header is missing or invalid mime type + (false, _) => true, }; if !can_parse_json { @@ -744,7 +746,7 @@ mod tests { .to_http_parts(); let s = Json::::from_request(&req, &mut pl).await; - assert!(s.is_ok()) + assert!(s.is_ok()); } #[actix_rt::test]