Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion lib/types/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -136,7 +141,8 @@ function json (options) {
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
verify: verify,
verifyParsed: verifyParsed
})
}
}
Expand Down