@@ -38,9 +38,10 @@ const checkPatchOverrideSupport = function (req, res) {
3838 * @param {Object } res - Express response object
3939 * @param {Function } next - Express next middleware function
4040 */
41+ const SKIP_CONTENT_TYPE_METHODS = [ "GET" , "HEAD" , "OPTIONS" , "DELETE" ]
42+
4143const validateContentType = function ( req , res , next ) {
42- const skipMethods = [ "GET" , "HEAD" , "OPTIONS" , "DELETE" ]
43- if ( skipMethods . includes ( req . method ) ) {
44+ if ( SKIP_CONTENT_TYPE_METHODS . includes ( req . method ) ) {
4445 return next ( )
4546 }
4647 const contentType = ( req . get ( "Content-Type" ) ?? "" ) . toLowerCase ( )
@@ -49,9 +50,10 @@ const validateContentType = function (req, res, next) {
4950 res . status ( 415 )
5051 return next ( res )
5152 }
52- if ( contentType . includes ( "application/json" ) || contentType . includes ( "application/ld+json" ) ) return next ( )
53+ const mimeType = contentType . split ( ";" ) [ 0 ] . trim ( )
54+ if ( mimeType === "application/json" || mimeType === "application/ld+json" ) return next ( )
5355 const isSearchEndpoint = req . path . startsWith ( "/search" )
54- if ( contentType . includes ( "text/plain" ) && isSearchEndpoint ) return next ( )
56+ if ( mimeType === "text/plain" && isSearchEndpoint ) return next ( )
5557 const acceptedTypes = `"application/json" or "application/ld+json"${ isSearchEndpoint ? ' or "text/plain"' : '' } `
5658 res . statusMessage = `Unsupported Content-Type: "${ contentType } ". This endpoint requires ${ acceptedTypes } .`
5759 res . status ( 415 )
0 commit comments