Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing maxBodyLength enforcement #3786

Merged
merged 3 commits into from Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/adapters/http.js
Expand Up @@ -101,6 +101,10 @@ module.exports = function httpAdapter(config) {
));
}

if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
return reject(createError('Request body larger than maxBodyLength limit', config));
}

// Add Content-Length header if data exists
if (!headerNames['content-length']) {
headers['Content-Length'] = data.length;
Expand Down
1 change: 0 additions & 1 deletion test/unit/adapters/http.js
Expand Up @@ -456,7 +456,6 @@ describe('supports http with nodejs', function () {
setTimeout(function () {
assert.equal(success, false, 'request should not succeed');
assert.equal(failure, true, 'request should fail');
assert.equal(error.code, 'ERR_FR_MAX_BODY_LENGTH_EXCEEDED');
assert.equal(error.message, 'Request body larger than maxBodyLength limit');
done();
}, 100);
Expand Down