From 0889c1531e70a3b6bc398fd5b70fa91d74c42da2 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 26 Jan 2026 19:53:01 +0100 Subject: [PATCH] Optionally allow json middleware to not check the content-type --- src/middleware/json.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middleware/json.js b/src/middleware/json.js index 0f73ddd98..a3c45d3f6 100644 --- a/src/middleware/json.js +++ b/src/middleware/json.js @@ -7,12 +7,12 @@ function _mime(req) { return str.split(';')[0]; } -exports = module.exports = function (options) { +exports = module.exports = function (options, forceContentType = true) { const json = express.json(options); return function (req, res, next) { // enforce json body type. without this the json middleware will skip parsing and req.body might be undefined - if (_mime(req) !== 'application/json') return res.status(400).send('incorrect mime type. expecting application/json'); + if (forceContentType && _mime(req) !== 'application/json') return res.status(400).send('incorrect mime type. expecting application/json'); json(req, res, next); }; };