diff --git a/lib/read.js b/lib/read.js index bf1a1df4..f79e042a 100644 --- a/lib/read.js +++ b/lib/read.js @@ -79,38 +79,37 @@ function read (req, res, next, parse, debug, options) { } let length - const opts = options let stream - // read options - const verify = opts.verify + const verify = options.verify try { // get the content stream - stream = contentstream(req, debug, opts.inflate) + stream = contentstream(req, debug, options.inflate) length = stream.length stream.length = undefined } catch (err) { return next(err) } - // set raw-body options - opts.length = length - opts.encoding = verify - ? null - : encoding - // assert charset is supported - if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) { + if (verify && encoding !== null && !iconv.encodingExists(encoding)) { return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', { charset: encoding.toLowerCase(), type: 'charset.unsupported' })) } + // set raw-body options + const rawBodyOptions = { + length, + encoding: verify ? null : encoding, + limit: options.limit + } + // read body debug('read body') - getBody(stream, opts, function (error, body) { + getBody(stream, rawBodyOptions, function (error, body) { if (error) { let _error