From 164887abb59c6ec08b3c3c54fd5d083a5bf12414 Mon Sep 17 00:00:00 2001 From: Adam Olley Date: Tue, 29 Mar 2022 21:33:44 +1030 Subject: [PATCH] Treat JSON API responses as the text they are The content-type "application/vnd.api/json" is a text based JSON response type. Lets treat it as such. Refernce: https://jsonapi.org/format/ --- response.go | 2 +- response_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/response.go b/response.go index 22c6664..cb10757 100644 --- a/response.go +++ b/response.go @@ -118,7 +118,7 @@ func isTextMime(kind string) bool { } switch mt { - case "image/svg+xml", "application/json", "application/xml","application/javascript": + case "image/svg+xml", "application/json", "application/xml", "application/javascript", "application/vnd.api+json": return true default: return false diff --git a/response_test.go b/response_test.go index 47e1357..48a7253 100644 --- a/response_test.go +++ b/response_test.go @@ -13,6 +13,12 @@ func Test_JSON_isTextMime(t *testing.T) { assert.Equal(t, isTextMime("Application/JSON"), true) } +func Test_JSONAPI_isTextMime(t *testing.T) { + assert.Equal(t, isTextMime("application/vnd.api+json"), true) + assert.Equal(t, isTextMime("application/vnd.api+json; charset=utf-8"), true) + assert.Equal(t, isTextMime("Application/VND.API+JSON"), true) +} + func Test_XML_isTextMime(t *testing.T) { assert.Equal(t, isTextMime("application/xml"), true) assert.Equal(t, isTextMime("application/xml; charset=utf-8"), true)