got 5.5.1 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +9 -3
- package/package.json +1 -1
- package/readme.md +10 -5
package/index.js
CHANGED
|
@@ -36,7 +36,7 @@ function requestAsEventEmitter(opts) {
|
|
|
36
36
|
var req = fn.request(opts, function (res) {
|
|
37
37
|
var statusCode = res.statusCode;
|
|
38
38
|
|
|
39
|
-
if (isRedirect(statusCode) && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {
|
|
39
|
+
if (isRedirect(statusCode) && opts.followRedirect && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {
|
|
40
40
|
res.resume();
|
|
41
41
|
|
|
42
42
|
if (++redirectCount > 10) {
|
|
@@ -96,13 +96,14 @@ function asCallback(opts, cb) {
|
|
|
96
96
|
ee.on('response', function (res) {
|
|
97
97
|
readAllStream(res, opts.encoding, function (err, data) {
|
|
98
98
|
var statusCode = res.statusCode;
|
|
99
|
+
var limitStatusCode = opts.followRedirect ? 299 : 399;
|
|
99
100
|
|
|
100
101
|
if (err) {
|
|
101
102
|
cb(new got.ReadError(err, opts), null, res);
|
|
102
103
|
return;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
if (statusCode < 200 || statusCode >
|
|
106
|
+
if (statusCode < 200 || statusCode > limitStatusCode) {
|
|
106
107
|
err = new got.HTTPError(statusCode, opts);
|
|
107
108
|
}
|
|
108
109
|
|
|
@@ -183,10 +184,11 @@ function asStream(opts) {
|
|
|
183
184
|
|
|
184
185
|
ee.on('response', function (res) {
|
|
185
186
|
var statusCode = res.statusCode;
|
|
187
|
+
var limitStatusCode = opts.followRedirect ? 299 : 399;
|
|
186
188
|
|
|
187
189
|
res.pipe(output);
|
|
188
190
|
|
|
189
|
-
if (statusCode < 200 || statusCode >
|
|
191
|
+
if (statusCode < 200 || statusCode > limitStatusCode) {
|
|
190
192
|
proxy.emit('error', new got.HTTPError(statusCode, opts), null, res);
|
|
191
193
|
return;
|
|
192
194
|
}
|
|
@@ -286,6 +288,10 @@ function normalizeArguments(url, opts) {
|
|
|
286
288
|
};
|
|
287
289
|
}
|
|
288
290
|
|
|
291
|
+
if (opts.followRedirect === undefined) {
|
|
292
|
+
opts.followRedirect = true;
|
|
293
|
+
}
|
|
294
|
+
|
|
289
295
|
return opts;
|
|
290
296
|
}
|
|
291
297
|
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -121,12 +121,19 @@ Milliseconds after which the request will be aborted and an error event with `ET
|
|
|
121
121
|
Type: `number`, `function`
|
|
122
122
|
Default: `5`
|
|
123
123
|
|
|
124
|
-
Number of request retries when network errors happens. Delays between retries counts with function `Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 0).
|
|
125
|
-
|
|
126
|
-
**Note:** `ENOTFOUND` and `ENETUNREACH` error will not be retried (see full list in [`is-retry-allowed`](https://github.com/floatdrop/is-retry-allowed/blob/master/index.js#L12) module).
|
|
124
|
+
Number of request retries when network errors happens. Delays between retries counts with function `1000 * Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 0).
|
|
127
125
|
|
|
128
126
|
Option accepts `function` with `retry` and `error` arguments. Function must return delay in milliseconds (`0` return value cancels retry).
|
|
129
127
|
|
|
128
|
+
**Note:** if `retries` is `number`, `ENOTFOUND` and `ENETUNREACH` error will not be retried (see full list in [`is-retry-allowed`](https://github.com/floatdrop/is-retry-allowed/blob/master/index.js#L12) module).
|
|
129
|
+
|
|
130
|
+
###### followRedirect
|
|
131
|
+
|
|
132
|
+
Type: `boolean`
|
|
133
|
+
Default: `true`
|
|
134
|
+
|
|
135
|
+
Defines if redirect responses should be followed automatically.
|
|
136
|
+
|
|
130
137
|
##### callback(error, data, response)
|
|
131
138
|
|
|
132
139
|
Function to be called when error or data are received. If omitted, a promise will be returned.
|
|
@@ -135,8 +142,6 @@ Function to be called when error or data are received. If omitted, a promise wil
|
|
|
135
142
|
|
|
136
143
|
`Error` object with HTTP status code as `statusCode` property.
|
|
137
144
|
|
|
138
|
-
###### data
|
|
139
|
-
|
|
140
145
|
The data you requested.
|
|
141
146
|
|
|
142
147
|
###### response
|