aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/store.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 05:29:49 +0100
committertv <tv@krebsco.de>2026-10-31 05:29:49 +0100
commitf72c751c837a41b807fe09cebe79e78a31309def (patch)
tree8d2fbdd4cc5ce90043bb91213d637c043e190676 /src/api/store.rs
parent9c45cb3e478a519182a7d9bf48af1529b2ccc457 (diff)
api: unify media-type stripping
Diffstat (limited to 'src/api/store.rs')
-rw-r--r--src/api/store.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/api/store.rs b/src/api/store.rs
index c67df85..274ca70 100644
--- a/src/api/store.rs
+++ b/src/api/store.rs
@@ -20,7 +20,7 @@ use tokio::sync::broadcast;
use tracing::{debug, error, instrument, warn};
use super::auth::AuthenticatedUser;
-use super::{ApiError, store_status};
+use super::{ApiError, media_type, store_status};
use crate::document::meta;
use crate::document::store::{self, StoreError, paths_related};
use crate::state::{AppState, ReadSource};
@@ -258,7 +258,7 @@ fn response_for_value(
.is_some_and(|value| {
value
.split(',')
- .any(|item| item.trim().starts_with("text/plain"))
+ .any(|item| media_type(item) == "text/plain")
});
let (content_type, body) = if wants_text {
@@ -296,12 +296,8 @@ fn body_value(headers: &HeaderMap, body: &Bytes) -> Result<JsonValue, StatusCode
let content_type = headers
.get(CONTENT_TYPE)
.and_then(|value| value.to_str().ok())
- .unwrap_or("application/json")
- .split(';')
- .next()
- .unwrap_or("")
- .trim();
- match content_type {
+ .unwrap_or("application/json");
+ match media_type(content_type) {
"application/json" => {
serde_json::from_slice::<JsonValue>(body).map_err(|_| StatusCode::BAD_REQUEST)
}