From f32dd98adbccd474a7751516ee35d08a0c3e08a6 Mon Sep 17 00:00:00 2001 From: Justin Reynolds Date: Thu, 28 Nov 2019 21:05:32 -0600 Subject: [PATCH] Fix charset encoding header --- lib/router.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/router.js b/lib/router.js index e69726f7..a41b3855 100644 --- a/lib/router.js +++ b/lib/router.js @@ -55,8 +55,12 @@ router.applyMiddleware = () => { if (req.headers.accept) { // 406 Not Acceptable let matchingTypes = req.headers.accept.split(/, ?/) - matchingTypes = matchingTypes.filter(mediaType => // Accept application/*, */vnd.api+json, */* and the correct JSON:API type. - mediaType.match(/^(\*|application)\/(\*|json|vnd\.api\+json)$/) || mediaType.match(/\*\/\*/)) + matchingTypes = matchingTypes.filter(mediaType => { + // Remove charset encoding + const type = mediaType.split(';')[0] + // Accept application/*, */vnd.api+json, */* and the correct JSON:API type. + return type.match(/^(\*|application)\/(\*|json|vnd\.api\+json)$/) || type.match(/\*\/\*/) + }) if (matchingTypes.length === 0) { return res.status(406).end()