diff --git a/axum/src/json.rs b/axum/src/json.rs index c62c94c6..1e662cc6 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -136,22 +136,14 @@ where } fn json_content_type(headers: &HeaderMap) -> bool { - let Some(content_type) = headers.get(header::CONTENT_TYPE) else { - return false; - }; - - let Ok(content_type) = content_type.to_str() else { - return false; - }; - - let Ok(mime) = content_type.parse::() else { - return false; - }; - - let is_json_content_type = mime.type_() == "application" - && (mime.subtype() == "json" || mime.suffix().is_some_and(|name| name == "json")); - - is_json_content_type + headers + .get(header::CONTENT_TYPE) + .and_then(|content_type| content_type.to_str().ok()) + .and_then(|content_type| content_type.parse::().ok()) + .is_some_and(|mime| { + mime.type_() == "application" + && (mime.subtype() == "json" || mime.suffix().is_some_and(|name| name == "json")) + }) } axum_core::__impl_deref!(Json);