Skip to content

Commit d90bb00

Browse files
authored
Merge pull request #124 from avorima/disable-redirects
feat: Allow configuring max redirects
2 parents b686156 + ebee4f4 commit d90bb00

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/proto/http.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ module.exports = {
2525
//max retry count will default to 2 seconds if not provided in options
2626
let retryCount = opts.retryCount || 2;
2727

28+
// allow disabling redirects with '0'. default to 8 if not provided in options
29+
let maxRedirects = (typeof opts.maxRedirects === 'number') ? opts.maxRedirects : 8;
30+
2831
//fallback retry delay will default to 60 seconds not provided in options
2932
let fallbackRetryDelayInMs = ms(opts.fallbackRetryDelay || '60s');
3033

@@ -42,7 +45,7 @@ module.exports = {
4245
agent: new ProxyAgent(),
4346
use_proxy_from_env_var: false,
4447
user_agent: user_agent,
45-
follow_max: 8,
48+
follow_max: maxRedirects,
4649
follow_keep_method: true,
4750
response_timeout: ms(timeout),
4851
open_timeout: ms(open_timeout),

test/link-check.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ describe('link-check', function () {
259259
});
260260
});
261261

262+
it('should allow disabling redirects', function (done) {
263+
linkCheck(baseUrl + '/foo/redirect', {maxRedirects: 0}, function (err, result) {
264+
expect(err).to.be(null);
265+
expect(result.link).to.be(baseUrl + '/foo/redirect');
266+
expect(result.status).to.be('dead');
267+
expect(result.statusCode).to.be(302);
268+
expect(result.err).to.be(null);
269+
done();
270+
});
271+
});
272+
262273
it('should handle valid mailto', function (done) {
263274
linkCheck('mailto:[email protected]', function (err, result) {
264275
expect(err).to.be(null);

0 commit comments

Comments
 (0)