Skip to content
Open
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
23 changes: 11 additions & 12 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down