mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-26 20:40:29 +00:00
Further refactor json_content_type
(#3340)
This commit is contained in:
parent
36f2630e4d
commit
df55d83f29
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user