Further refactor json_content_type (#3340)

This commit is contained in:
daalfox 2025-05-06 15:21:10 +03:30 committed by GitHub
parent 36f2630e4d
commit df55d83f29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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::<mime::Mime>() 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::<mime::Mime>().ok())
.is_some_and(|mime| {
mime.type_() == "application"
&& (mime.subtype() == "json" || mime.suffix().is_some_and(|name| name == "json"))
})
}
axum_core::__impl_deref!(Json);