mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Fixing maxBodyLength enforcement (#3786)
* Adding request body length validation on HTTP adapter * Removing error code assertion on HTTP's body length support test * Removed due to the error being thrown by axios itself now, instead of follow-redirects Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -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
|
// Add Content-Length header if data exists
|
||||||
if (!headerNames['content-length']) {
|
if (!headerNames['content-length']) {
|
||||||
headers['Content-Length'] = data.length;
|
headers['Content-Length'] = data.length;
|
||||||
|
|||||||
@@ -456,7 +456,6 @@ describe('supports http with nodejs', function () {
|
|||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
assert.equal(success, false, 'request should not succeed');
|
assert.equal(success, false, 'request should not succeed');
|
||||||
assert.equal(failure, true, 'request should fail');
|
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');
|
assert.equal(error.message, 'Request body larger than maxBodyLength limit');
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|||||||
Reference in New Issue
Block a user