Skip to content

Commit 2e014d7

Browse files
committed
Changes while reviewing
1 parent 5b91d8d commit 2e014d7

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

rest.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const checkPatchOverrideSupport = function (req, res) {
2525
}
2626

2727
/**
28-
* Middleware to validate Content-Type headers on API write endpoints.
28+
* Middleware to validate Content-Type headers.
2929
* Ensures that requests carrying bodies have an appropriate Content-Type before
3030
* reaching controllers, preventing unhandled errors from unparsed or mis-parsed bodies.
3131
*
@@ -43,27 +43,15 @@ const validateContentType = function (req, res, next) {
4343
if (skipMethods.includes(req.method)) {
4444
return next()
4545
}
46-
4746
const contentType = req.get("Content-Type") ?? ""
48-
4947
if (!contentType) {
5048
res.statusMessage = `Missing Content-Type header. Requests to this endpoint require a Content-Type of "application/json" or "application/ld+json".`
5149
res.status(415)
5250
return next(res)
5351
}
54-
55-
const isJson = contentType.includes("application/json") || contentType.includes("application/ld+json")
56-
const isText = contentType.includes("text/plain")
52+
if (contentType.includes("application/json") || contentType.includes("application/ld+json")) return next()
5753
const isSearchEndpoint = req.path.startsWith("/search")
58-
59-
if (isJson) {
60-
return next()
61-
}
62-
63-
if (isText && isSearchEndpoint) {
64-
return next()
65-
}
66-
54+
if (contentType.includes("text/plain") && isSearchEndpoint) return next()
6755
const acceptedTypes = `"application/json" or "application/ld+json"${isSearchEndpoint ? ' or "text/plain"' : ''}`
6856
res.statusMessage = `Unsupported Content-Type: "${contentType}". This endpoint requires ${acceptedTypes}.`
6957
res.status(415)

0 commit comments

Comments
 (0)