Skip to content

Commit c02fe7f

Browse files
committed
Changes while reviewing
1 parent 1190481 commit c02fe7f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const validateContentType = function (req, res, next) {
4343
if (skipMethods.includes(req.method)) {
4444
return next()
4545
}
46-
const contentType = req.get("Content-Type") ?? ""
46+
const contentType = (req.get("Content-Type") ?? "").toLowerCase()
4747
if (!contentType) {
4848
res.statusMessage = `Missing Content-Type header.`
4949
res.status(415)

routes/__tests__/contentType.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ describe("Content-Type validation middleware", () => {
102102
expect(response.body.received.searchText).toBe("hello")
103103
})
104104

105+
it("accepts Content-Type with unusual casing", async () => {
106+
const response = await request(routeTester)
107+
.post("/api/create")
108+
.set("Content-Type", "Application/JSON")
109+
.send({ test: "casing" })
110+
expect(response.statusCode).toBe(200)
111+
expect(response.body.received.test).toBe("casing")
112+
})
113+
105114
it("skips validation for GET requests", async () => {
106115
const response = await request(routeTester)
107116
.get("/api/info")

0 commit comments

Comments
 (0)