diff --git a/lib/read.js b/lib/read.js index fce6283f..5fc519f5 100644 --- a/lib/read.js +++ b/lib/read.js @@ -50,6 +50,7 @@ function read (req, res, next, parse, debug, options) { ? opts.encoding : null var verify = opts.verify + var verifyParsed = opts.verifyParsed try { // get the content stream @@ -125,7 +126,11 @@ function read (req, res, next, parse, debug, options) { str = typeof body !== 'string' && encoding !== null ? iconv.decode(body, encoding) : body - req.body = parse(str) + var parsedBody = parse(str) + if (verifyParsed) { + verifyParsed(req, res, parsedBody) + } + req.body = parsedBody } catch (err) { next(createError(400, err, { body: str, diff --git a/lib/types/json.js b/lib/types/json.js index c2745be3..0704f28e 100644 --- a/lib/types/json.js +++ b/lib/types/json.js @@ -58,11 +58,16 @@ function json (options) { var strict = opts.strict !== false var type = opts.type || 'application/json' var verify = opts.verify || false + var verifyParsed = opts.verifyParsed || false if (verify !== false && typeof verify !== 'function') { throw new TypeError('option verify must be function') } + if (verifyParsed !== false && typeof verifyParsed !== 'function') { + throw new TypeError('option verifyParsed must be function') + } + // create the appropriate type checking function var shouldParse = typeof type !== 'function' ? typeChecker(type) @@ -136,7 +141,8 @@ function json (options) { encoding: charset, inflate: inflate, limit: limit, - verify: verify + verify: verify, + verifyParsed: verifyParsed }) } }