When you type app.use(express.bodyParser()) almost every request will go through the bodyParser functions (which one will be executed depends on the Content-Type header).
By default, 3 headers are supported (AFAIR). You can make sure the sources are sure. You can (re) define handlers for the Content-Type with something like this:
var express = require('express'); var bodyParser = express.bodyParser; // redefine handler for Content-Type: multipart/form-data bodyParser.parse('multipart/form-data') = function(req, options, next) { // parse request body your way; example of such action: // https://github.com/senchalabs/connect/blob/master/lib/middleware/multipart.js // for your needs it will probably be this: next(); }
<h / "> UPD.
In Express 3, everything has changed, so I use the updated code from a working draft (should be app.use ed before express.bodyParser() ):
var connectUtils = require('express/node_modules/connect/lib/utils'); module.exports = function(contentTypes) { contentTypes = Array.isArray(contentTypes) ? contentTypes : [contentTypes]; return function (req, res, next) { if (req._body) return next(); req.body = req.body || {}; if (!connectUtils.hasBody(req)) return next(); if (-1 === contentTypes.indexOf(req.header('content-type'))) return next(); req.setEncoding('utf8');
And some pseudo code related to the original question:
function disableParserForContentType(req, res, next) { if (req.contentType in options.contentTypes) { req._body = true; next(); } }
elmigranto Jul 04 2018-12-12T00: 00Z
source share