Skip to content

Commit 0f5fa25

Browse files
committed
Changes while reviewing
1 parent 1a33fe1 commit 0f5fa25

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

rest.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ const checkPatchOverrideSupport = function (req, res) {
4242
*/
4343
const SKIP_CONTENT_TYPE_METHODS = ["GET", "HEAD", "OPTIONS", "DELETE"]
4444
const validateContentType = function (req, res, next) {
45-
if (SKIP_CONTENT_TYPE_METHODS.includes(req.method) || req.path.startsWith("/release")) {
45+
const isReleaseEndpoint = req.path === "/release" || req.path.startsWith("/release/")
46+
if (SKIP_CONTENT_TYPE_METHODS.includes(req.method) || isReleaseEndpoint) {
4647
return next()
4748
}
4849
const contentType = (req.get("Content-Type") ?? "").toLowerCase()
49-
if (!contentType) {
50+
const mimeType = contentType.split(";")[0].trim()
51+
if (!mimeType) {
5052
return next(createExpressError({
5153
statusCode: 415,
52-
statusMessage: `Missing Content-Type header.`
54+
statusMessage: `Missing or empty Content-Type header.`
5355
}))
5456
}
55-
const mimeType = contentType.split(";")[0].trim()
5657
if (mimeType === "application/json" || mimeType === "application/ld+json") return next()
5758
const isSearchEndpoint = req.path === "/search" || req.path.startsWith("/search/")
5859
if (mimeType === "text/plain" && isSearchEndpoint) return next()

routes/__tests__/contentType.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("Content-Type validation middleware", () => {
6363
.unset("Content-Type")
6464
.send(Buffer.from('{"test":"data"}'))
6565
expect(response.statusCode).toBe(415)
66-
expect(response.text).toContain("Missing Content-Type header")
66+
expect(response.text).toContain("Missing or empty Content-Type header")
6767
})
6868

6969
it("returns 415 for text/plain on JSON-only endpoint", async () => {

0 commit comments

Comments
 (0)