Skip to content

Commit

Permalink
lib/request-browser: add maxRedirects option.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Dec 16, 2023
1 parent b6557dd commit 13d28e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/request-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RequestOptions {
this.username = '';
this.password = '';
this.limit = 20 << 20;
this.maxRedirects = 5;
this.timeout = 5000;
this.buffer = buffer || false;
this.headers = Object.create(null);
Expand Down Expand Up @@ -151,6 +152,11 @@ class RequestOptions {
this.limit = options.limit;
}

if (options.maxRedirects != null) {
assert(typeof options.maxRedirects === 'number');
this.maxRedirects = options.maxRedirects;
}

if (options.headers != null) {
assert(typeof options.headers === 'object');
this.headers = options.headers;
Expand Down Expand Up @@ -277,7 +283,7 @@ class RequestOptions {
mode: 'cors',
credentials: auth ? 'include' : 'omit',
cache: 'no-store',
redirect: 'follow',
redirect: this.maxRedirects ? 'follow' : 'error',
referrer
};

Expand Down

0 comments on commit 13d28e5

Please sign in to comment.