Skip to content

Commit

Permalink
Merge pull request #917 from restify/fix-node-4-tests
Browse files Browse the repository at this point in the history
Fix: HTTP 413 status name (fixes #916)

Fixes #916 by falling back to the old HTTP 413 Error Code if not present
  • Loading branch information
micahr committed Sep 18, 2015
2 parents eb98cec + 9aa1eeb commit c803dbb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"no-dupe-keys": [ 2 ],
"no-duplicate-case": [ 2 ],
"no-empty": [ 2 ],
"no-empty-class": [ 2 ],
"no-empty-character-class": [ 2 ],
"no-ex-assign": [ 2 ],
"no-extra-boolean-cast": [ 2 ],
"no-extra-semi": [ 2 ],
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "stable"
notifications:
webhooks:
urls:
Expand Down
19 changes: 16 additions & 3 deletions lib/plugins/body_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var errors = require('../errors');

var BadDigestError = errors.BadDigestError;
var RequestEntityTooLargeError = errors.RequestEntityTooLargeError;
var PayloadTooLargeError = errors.PayloadTooLargeError;

var MD5_MSG = 'Content-MD5 \'%s\' didn\'t match \'%s\'';

Expand Down Expand Up @@ -56,7 +57,7 @@ function createBodyWriter(req) {
* reads the body of the request.
* @public
* @function bodyReader
* @throws {BadDigestError | RequestEntityTooLargeError}
* @throws {BadDigestError | PayloadTooLargeError}
* @param {Object} options an options object
* @returns {Function}
*/
Expand Down Expand Up @@ -86,12 +87,23 @@ function bodyReader(options) {
}

function done() {
var errorMessage;
bodyWriter.end();

if (maxBodySize && bytesReceived > maxBodySize) {
var msg = 'Request body size exceeds ' +
maxBodySize;
next(new RequestEntityTooLargeError(msg));

// Between Node 0.12 and 4 http status code messages changed
// RequestEntityTooLarge was changed to PayloadTooLarge
// this check is to maintain backwards compatibility
if (PayloadTooLargeError !== undefined) {
errorMessage = new PayloadTooLargeError(msg);
} else {
errorMessage = new RequestEntityTooLargeError(msg);
}

next(errorMessage);
return;
}

Expand All @@ -101,7 +113,8 @@ function bodyReader(options) {
}

if (hash && md5 !== (digest = hash.digest('base64'))) {
next(new BadDigestError(MD5_MSG, md5, digest));
errorMessage = new BadDigestError(MD5_MSG, md5, digest);
next(errorMessage);
return;
}

Expand Down

0 comments on commit c803dbb

Please sign in to comment.