From 4491c33cb01865517b569367ce602e812e7e38ff Mon Sep 17 00:00:00 2001 From: aumetra Date: Sat, 2 Dec 2023 16:22:28 +0100 Subject: [PATCH] change extractor internals --- kitsune/src/http/extractor/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kitsune/src/http/extractor/mod.rs b/kitsune/src/http/extractor/mod.rs index d6241b982..d816c39be 100644 --- a/kitsune/src/http/extractor/mod.rs +++ b/kitsune/src/http/extractor/mod.rs @@ -7,6 +7,7 @@ use axum::{ Form, RequestExt, TypedHeader, }; use headers::ContentType; +use http::StatusCode; use mime::Mime; use serde::de::DeserializeOwned; @@ -41,20 +42,21 @@ where .extract_parts::>() .await .map_err(IntoResponse::into_response)?; + let content_type = Mime::from(content_type); - let content = if Mime::from(content_type) - .as_ref() - .starts_with(mime::APPLICATION_WWW_FORM_URLENCODED.as_ref()) - { + let content = if content_type.essence_str() == mime::APPLICATION_WWW_FORM_URLENCODED { Form::from_request(req, state) .await .map_err(IntoResponse::into_response)? .0 - } else { + } else if content_type.essence_str() == mime::APPLICATION_JSON { Json::from_request(req, state) .await .map_err(IntoResponse::into_response)? .0 + } else { + error!(%content_type, "Unknown content type"); + return Err(StatusCode::UNPROCESSABLE_ENTITY.into_response()); }; Ok(Self(content))