Skip to content

Commit df55d83

Browse files
authored
Further refactor json_content_type (#3340)
1 parent 36f2630 commit df55d83

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

axum/src/json.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,14 @@ where
136136
}
137137

138138
fn json_content_type(headers: &HeaderMap) -> bool {
139-
let Some(content_type) = headers.get(header::CONTENT_TYPE) else {
140-
return false;
141-
};
142-
143-
let Ok(content_type) = content_type.to_str() else {
144-
return false;
145-
};
146-
147-
let Ok(mime) = content_type.parse::<mime::Mime>() else {
148-
return false;
149-
};
150-
151-
let is_json_content_type = mime.type_() == "application"
152-
&& (mime.subtype() == "json" || mime.suffix().is_some_and(|name| name == "json"));
153-
154-
is_json_content_type
139+
headers
140+
.get(header::CONTENT_TYPE)
141+
.and_then(|content_type| content_type.to_str().ok())
142+
.and_then(|content_type| content_type.parse::<mime::Mime>().ok())
143+
.is_some_and(|mime| {
144+
mime.type_() == "application"
145+
&& (mime.subtype() == "json" || mime.suffix().is_some_and(|name| name == "json"))
146+
})
155147
}
156148

157149
axum_core::__impl_deref!(Json);

0 commit comments

Comments
 (0)