diff options
| author | tv <tv@krebsco.de> | 2026-10-31 05:29:49 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 05:29:49 +0100 |
| commit | ca0bd76db94e5d561f5c30b7b211e865d9e9e494 (patch) | |
| tree | 74ef8413967a9ccb7dc042854d88d79bcae67aa4 /src/api/store.rs | |
| parent | c76fd5b9b0a3bba6c8ffa847e5fc818661e800d6 (diff) | |
api: unify media-type stripping
Diffstat (limited to 'src/api/store.rs')
| -rw-r--r-- | src/api/store.rs | 12 |
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) } |
