Skip to content

Commit c803dbb

Browse files
committed
Merge pull request #917 from restify/fix-node-4-tests
Fix: HTTP 413 status name (fixes #916) Fixes #916 by falling back to the old HTTP 413 Error Code if not present
2 parents eb98cec + 9aa1eeb commit c803dbb

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"no-dupe-keys": [ 2 ],
1616
"no-duplicate-case": [ 2 ],
1717
"no-empty": [ 2 ],
18-
"no-empty-class": [ 2 ],
18+
"no-empty-character-class": [ 2 ],
1919
"no-ex-assign": [ 2 ],
2020
"no-extra-boolean-cast": [ 2 ],
2121
"no-extra-semi": [ 2 ],

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ language: node_js
33
node_js:
44
- "0.10"
55
- "0.12"
6+
- "4"
7+
- "stable"
68
notifications:
79
webhooks:
810
urls:

lib/plugins/body_reader.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var errors = require('../errors');
1414

1515
var BadDigestError = errors.BadDigestError;
1616
var RequestEntityTooLargeError = errors.RequestEntityTooLargeError;
17+
var PayloadTooLargeError = errors.PayloadTooLargeError;
1718

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

@@ -56,7 +57,7 @@ function createBodyWriter(req) {
5657
* reads the body of the request.
5758
* @public
5859
* @function bodyReader
59-
* @throws {BadDigestError | RequestEntityTooLargeError}
60+
* @throws {BadDigestError | PayloadTooLargeError}
6061
* @param {Object} options an options object
6162
* @returns {Function}
6263
*/
@@ -86,12 +87,23 @@ function bodyReader(options) {
8687
}
8788

8889
function done() {
90+
var errorMessage;
8991
bodyWriter.end();
9092

9193
if (maxBodySize && bytesReceived > maxBodySize) {
9294
var msg = 'Request body size exceeds ' +
9395
maxBodySize;
94-
next(new RequestEntityTooLargeError(msg));
96+
97+
// Between Node 0.12 and 4 http status code messages changed
98+
// RequestEntityTooLarge was changed to PayloadTooLarge
99+
// this check is to maintain backwards compatibility
100+
if (PayloadTooLargeError !== undefined) {
101+
errorMessage = new PayloadTooLargeError(msg);
102+
} else {
103+
errorMessage = new RequestEntityTooLargeError(msg);
104+
}
105+
106+
next(errorMessage);
95107
return;
96108
}
97109

@@ -101,7 +113,8 @@ function bodyReader(options) {
101113
}
102114

103115
if (hash && md5 !== (digest = hash.digest('base64'))) {
104-
next(new BadDigestError(MD5_MSG, md5, digest));
116+
errorMessage = new BadDigestError(MD5_MSG, md5, digest);
117+
next(errorMessage);
105118
return;
106119
}
107120

0 commit comments

Comments
 (0)