diff --git a/src/workerd/util/mimetype-test.c++ b/src/workerd/util/mimetype-test.c++ index 87a52310c86..7e26af3ede5 100644 --- a/src/workerd/util/mimetype-test.c++ +++ b/src/workerd/util/mimetype-test.c++ @@ -464,6 +464,23 @@ KJ_TEST("Quoted-string escape handling") { } } +KJ_TEST("AWS JSON MIME types are classified as text") { + static constexpr kj::StringPtr supportedTypes[] = { + "application/x-amz-json-1.0"_kj, + "application/x-amz-json-1.1"_kj, + }; + + for (const auto& input: supportedTypes) { + auto mimeType = KJ_ASSERT_NONNULL(MimeType::tryParse(input)); + KJ_ASSERT(MimeType::isText(mimeType)); + KJ_ASSERT(!MimeType::isJson(mimeType)); + } + + auto unsupportedType = KJ_ASSERT_NONNULL(MimeType::tryParse("application/x-amz-json-1.2"_kj)); + KJ_ASSERT(!MimeType::isText(unsupportedType)); + KJ_ASSERT(!MimeType::isJson(unsupportedType)); +} + KJ_TEST("Backslash escaping in serialization round-trips") { // A value containing both backslash and non-token chars must be quoted // with the backslash escaped, and the result must round-trip. diff --git a/src/workerd/util/mimetype.h b/src/workerd/util/mimetype.h index 1c4b9dac31a..c4e3606b66c 100644 --- a/src/workerd/util/mimetype.h +++ b/src/workerd/util/mimetype.h @@ -146,7 +146,8 @@ class MimeType final { auto type = mimeType.type(); auto subtype = mimeType.subtype(); return type == "text" || isXml(mimeType) || isJson(mimeType) || isJavascript(mimeType) || - (type == "application" && subtype == "dns-json"); + (type == "application" && + (subtype == "dns-json" || subtype == "x-amz-json-1.0" || subtype == "x-amz-json-1.1")); } template