Improve raw body parser to handle skipped parsing and ended streams

This commit is contained in:
Debadutta Panda
2025-07-26 02:04:01 +05:30
parent 6fcba3bfab
commit f57d7d9382

View File

@@ -30,8 +30,8 @@ module.exports = function(RED) {
var rawDataRoutes = new Set();
function rawBodyParser(req, res, next) {
if (req.skipRawBodyParser) { next(); } // don't parse this if told to skip
if (req._body) { return next(); }
if (req.skipRawBodyParser || req._body || req.readableEnded) return next();
req.body = "";
req._body = true;
@@ -323,7 +323,9 @@ module.exports = function(RED) {
if (this.upload) {
var mp = multer({ storage: multer.memoryStorage() }).any();
multipartParser = function(req,res,next) {
if(req.readableEnded || req._body) return next();
mp(req,res,function(err) {
req._body = true;
next(err);
})
};