diff --git a/Cargo.lock b/Cargo.lock index b7b402f..1c3b175 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1105,6 +1105,7 @@ name = "duperfmt" version = "0.1.1" dependencies = [ "clap", + "insta", "miette", "thiserror 2.0.17", "topiary-core", @@ -1723,9 +1724,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.43.2" +version = "1.44.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fdb647ebde000f43b5b53f773c30cf9b0cb4300453208713fa38b2c70935a0" +checksum = "b5c943d4415edd8153251b6f197de5eb1640e56d84e8d9159bea190421c73698" dependencies = [ "console", "once_cell", diff --git a/axum_duper/CHANGELOG.md b/axum_duper/CHANGELOG.md index 57698a4..1487eeb 100644 --- a/axum_duper/CHANGELOG.md +++ b/axum_duper/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changed - Bump `duper` to 0.6.0. +- Handle `Content-Type: application/json` requests in extractor. ## 0.4.2 (2025-12-07) diff --git a/axum_duper/src/lib.rs b/axum_duper/src/lib.rs index 2faafff..f54f5d6 100644 --- a/axum_duper/src/lib.rs +++ b/axum_duper/src/lib.rs @@ -18,8 +18,11 @@ use serde_core::{Serialize, de::DeserializeOwned}; /// Default MIME type for Duper files. pub static DUPER_CONTENT_TYPE: &str = "application/duper"; -/// Alternative MIME type for Duper files. +/// Alternative MIME type for Duper files, handled by the Duper extractor. pub static DUPER_ALT_CONTENT_TYPE: &str = "application/x-duper"; +/// Default MIME type for JSON files, handled by the Duper extractor (given +/// that Duper is a superset of JSON). +pub static JSON_CONTENT_TYPE: &str = "application/json"; /// Rejection used for [`Duper`]. /// @@ -168,15 +171,23 @@ where .headers() .get(CONTENT_TYPE) .and_then(|content_type| content_type.to_str().ok()) - && (content_type == DUPER_CONTENT_TYPE || content_type == DUPER_ALT_CONTENT_TYPE) { - let string = String::from_request(req, state) - .await - .map_err(|_| DuperRejection::DuperDataError)?; - Self::from_string(&string) - } else { - Err(DuperRejection::MissingDuperContentType) + let content_type = if let Some((content_type, _)) = content_type.split_once(';') { + content_type + } else { + content_type + }; + if content_type == DUPER_CONTENT_TYPE + || content_type == DUPER_ALT_CONTENT_TYPE + || content_type == JSON_CONTENT_TYPE + { + let string = String::from_request(req, state) + .await + .map_err(|_| DuperRejection::DuperDataError)?; + return Self::from_string(&string); + } } + Err(DuperRejection::MissingDuperContentType) } } diff --git a/duper-python/CHANGELOG.md b/duper-python/CHANGELOG.md index 6095b87..6bfd224 100644 --- a/duper-python/CHANGELOG.md +++ b/duper-python/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changed - Bump `duper` to 0.6.0. +- Handle `Content-Type: application/json` requests in FastAPI dependency. ## 0.4.2 (2025-12-07) diff --git a/duper-python/python/duper/fastapi.py b/duper-python/python/duper/fastapi.py index f1f7506..ad22aac 100644 --- a/duper-python/python/duper/fastapi.py +++ b/duper-python/python/duper/fastapi.py @@ -16,6 +16,7 @@ __all__ = [ DUPER_CONTENT_TYPE = "application/duper" DUPER_ALT_CONTENT_TYPE = "application/x-duper" +JSON_CONTENT_TYPE = "application/json" T = TypeVar("T") @@ -77,9 +78,11 @@ def DuperBody(model_type: type[T]) -> Any: # pyright: ignore[reportExplicitAny, """ async def _get_duper_body(request: Request) -> T: - if request.headers.get("Content-Type") not in ( + content_type = request.headers.get("Content-Type") + if not content_type or content_type.split(";", 1)[0] not in ( DUPER_CONTENT_TYPE, DUPER_ALT_CONTENT_TYPE, + JSON_CONTENT_TYPE, ): raise HTTPException( status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE, diff --git a/duper/Cargo.toml b/duper/Cargo.toml index b426028..7032890 100644 --- a/duper/Cargo.toml +++ b/duper/Cargo.toml @@ -30,5 +30,5 @@ serde_core = { version = "1", optional = true } unicode-general-category = "1" [dev-dependencies] -insta = "1.43.2" +insta = "1.44.3" serde = { version = "1.0.228", features = ["derive"] } diff --git a/duper_website/docs/spec.md b/duper_website/docs/spec.md index 11154d1..53793c2 100644 --- a/duper_website/docs/spec.md +++ b/duper_website/docs/spec.md @@ -1,5 +1,5 @@ --- -version: "0.4.1" +version: "0.4.2" ---