clarify comments for invalid json mime type

This commit is contained in:
Rob Ede 2023-11-19 11:07:53 +00:00
parent f7849d5e99
commit 925250370a
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 8 additions and 6 deletions

View File

@ -334,11 +334,13 @@ impl<T: DeserializeOwned> JsonBody<T> {
|| 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::<MyObject>::from_request(&req, &mut pl).await;
assert!(s.is_ok())
assert!(s.is_ok());
}
#[actix_rt::test]