Skip to content

Commit e9c9f33

Browse files
Fix/4263/maxbodylength defaults (axios#4731)
* test(http): add test case for default body length in follow-redirects * fix(http): provide proper default body length to follow-redirects Co-authored-by: Jay <jasonsaayman@gmail.com>
1 parent c30252f commit e9c9f33

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/adapters/http.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ module.exports = function httpAdapter(config) {
279279

280280
if (config.maxBodyLength > -1) {
281281
options.maxBodyLength = config.maxBodyLength;
282+
} else {
283+
// follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
284+
options.maxBodyLength = Infinity;
282285
}
283286

284287
if (config.insecureHTTPParser) {

test/unit/adapters/http.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,36 @@ describe('supports http with nodejs', function () {
566566
});
567567
});
568568

569+
it('should properly support default max body length (follow-redirects as well)', function (done) {
570+
// taken from https://github.com/follow-redirects/follow-redirects/blob/22e81fc37132941fb83939d1dc4c2282b5c69521/index.js#L461
571+
var followRedirectsMaxBodyDefaults = 10 * 1024 *1024;
572+
var data = Array(2 * followRedirectsMaxBodyDefaults).join('ж');
573+
574+
server = http.createServer(function (req, res) {
575+
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
576+
res.end();
577+
}).listen(4444, function () {
578+
var success = false, failure = false, error;
579+
// send using the default -1 (unlimited axios maxBodyLength)
580+
axios.post('http://localhost:4444/', {
581+
data: data
582+
}).then(function (res) {
583+
success = true;
584+
}).catch(function (err) {
585+
error = err;
586+
failure = true;
587+
});
588+
589+
590+
setTimeout(function () {
591+
assert.equal(success, true, 'request should have succeeded');
592+
assert.equal(failure, false, 'request should not fail');
593+
assert.equal(error, undefined, 'There should not be any error');
594+
done();
595+
}, 100);
596+
});
597+
});
598+
569599
it('should display error while parsing params', function (done) {
570600
server = http.createServer(function () {
571601

0 commit comments

Comments
 (0)