Skip to content

Commit

Permalink
fix(index): handle array of content-type headers (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored May 27, 2023
1 parent c19a9a5 commit b893bec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const secJSON = require("secure-json-parse");
async function fastifyJsonToXml(server, options) {
server.addHook("onSend", async (req, res, payload) => {
if (
res.getHeader("content-type")?.includes("application/json") &&
res
.getHeader("content-type")
?.toString()
?.includes("application/json") &&
accepts(req).type(["application/json", "application/xml"]) ===
"application/xml"
) {
Expand Down
7 changes: 7 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ describe("JSON-To-XML plugin", () => {
accept: "application/json",
},
},
{
testName:
"JSON body if 'application/json' before '*/*' in accept header",
headers: {
accept: "application/json, */*",
},
},
{
testName:
"JSON body if 'application/json' before 'application/xml' in accept header",
Expand Down

0 comments on commit b893bec

Please sign in to comment.