tokio-rs / axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper
19.03k stars 1.06k forks source link

Content-Type for Json does not support those of aws #2828

Closed ValentinColin closed 3 months ago

ValentinColin commented 3 months ago

Bug Report

Version

0.7.5

Platform

Linux x86_64

Crates

axum

Description

When I use the ContentType header application/x-amz-json-1.1 with a json body, I get the following error from JsonRejection

Expected request with `Content-Type: application/json`

Axum use the Mime crate to parse the the MediaType but it doesn't seem general enough.

jplatte commented 3 months ago

Axum use the Mime crate to parse the the MediaType but it doesn't seem general enough.

Sorry, but this is just Amazon doing weird things. I don't think that Content-Type value is something we should support in the Json extractor as long as it checks the content-type at all.

I would recommend that you look into why Amazon is sending this and if it can't be changed but is still regular JSON, either create a middleware that rewrites the header to application/json if it sees this special Amazon-specific value, or copy-paste the Json extractor into your codebase and adjust it to work as you need it.