Unobtrusive middle-ware for Expres.js to inspect request body -
does there exist thirdparty middleware or way create such middleware express.js allows intercepting requests , inspecting request's body content without affecting subsequent middleware such bodyparser or route endpoints may rely on raw body such express-http-proxy?
from can tell bodyparser seems work in obtrusive way not allow route override default parsing behavior. express documentation describes how request.body filled in middleware such bodyparser. behavior of bodyparser makes sense simplicity , performance perspective doesn't make great candidate creating middleware needs inspect contents of request , let remaining portion of app working without modification. true seeing depending on parsing middleware results may in entirely different formats. after digging i'm left wondering if it's possible pull off express or perhaps once read request body eliminate ability make use of further middleware such bodyparser or express-http-proxy expect access body directly.
possibly related:
you use raw-body package express middleware so:
var getrawbody = require('raw-body'); var typer = require('media-typer'); app.use(function (req, res, next) { getrawbody(req, { length: req.headers['content-length'], limit: '1mb', encoding: typer.parse(req.headers['content-type']).parameters.charset }, function (err, string) { if (err) return next(err) req.text = string next() }) })
if concern performance, wouldn't worry body-parser it's unlikely have massive performance impact. if can, i'd suggest use body-parser typical express middleware app.use(..)
inspect request body.
Comments
Post a Comment