Skip to content

Commit

Permalink
perf: remove argument reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 22, 2017
1 parent d5f9a4a commit 6339bf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "standard"
"extends": "standard",
"rules": {
"no-param-reassign": "error"
}
}
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ unreleased
==========

* deps: [email protected]
* perf: remove argument reassignment

1.18.1 / 2017-09-12
===================
Expand Down
17 changes: 11 additions & 6 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,25 @@ function read (req, res, next, parse, debug, options) {

// read body
debug('read body')
getBody(stream, opts, function (err, body) {
if (err) {
// echo back charset
if (err.type === 'encoding.unsupported') {
err = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
getBody(stream, opts, function (error, body) {
if (error) {
var _error

if (error.type === 'encoding.unsupported') {
// echo back charset
_error = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
charset: encoding.toLowerCase(),
type: 'charset.unsupported'
})
} else {
// set status code on error
_error = createError(400, error)
}

// read off entire request
stream.resume()
onFinished(req, function onfinished () {
next(createError(400, err))
next(createError(400, _error))
})
return
}
Expand Down

0 comments on commit 6339bf7

Please sign in to comment.