got 6.6.1 → 6.7.1
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 +21 -12
- package/package.json +9 -7
- package/readme.md +3 -1
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const EventEmitter = require('events')
|
|
2
|
+
const EventEmitter = require('events');
|
|
3
3
|
const http = require('http');
|
|
4
4
|
const https = require('https');
|
|
5
5
|
const PassThrough = require('stream').PassThrough;
|
|
@@ -14,9 +14,9 @@ const lowercaseKeys = require('lowercase-keys');
|
|
|
14
14
|
const isRedirect = require('is-redirect');
|
|
15
15
|
const unzipResponse = require('unzip-response');
|
|
16
16
|
const createErrorClass = require('create-error-class');
|
|
17
|
-
const nodeStatusCodes = require('node-status-codes');
|
|
18
17
|
const isRetryAllowed = require('is-retry-allowed');
|
|
19
|
-
const
|
|
18
|
+
const Buffer = require('safe-buffer').Buffer;
|
|
19
|
+
const pkg = require('./package');
|
|
20
20
|
|
|
21
21
|
function requestAsEventEmitter(opts) {
|
|
22
22
|
opts = opts || {};
|
|
@@ -41,7 +41,9 @@ function requestAsEventEmitter(opts) {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
const bufferString = Buffer.from(res.headers.location, 'binary').toString();
|
|
45
|
+
|
|
46
|
+
redirectUrl = urlLib.resolve(urlLib.format(opts), bufferString);
|
|
45
47
|
const redirectOpts = Object.assign({}, opts, urlLib.parse(redirectUrl));
|
|
46
48
|
|
|
47
49
|
ee.emit('redirect', res, redirectOpts);
|
|
@@ -71,11 +73,13 @@ function requestAsEventEmitter(opts) {
|
|
|
71
73
|
ee.emit('error', new got.RequestError(err, opts));
|
|
72
74
|
});
|
|
73
75
|
|
|
74
|
-
if (opts.
|
|
75
|
-
timedOut(req, opts.
|
|
76
|
+
if (opts.gotTimeout) {
|
|
77
|
+
timedOut(req, opts.gotTimeout);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
setImmediate(() =>
|
|
80
|
+
setImmediate(() => {
|
|
81
|
+
ee.emit('request', req);
|
|
82
|
+
});
|
|
79
83
|
};
|
|
80
84
|
|
|
81
85
|
get(opts);
|
|
@@ -285,6 +289,11 @@ function normalizeArguments(url, opts) {
|
|
|
285
289
|
opts.followRedirect = true;
|
|
286
290
|
}
|
|
287
291
|
|
|
292
|
+
if (opts.timeout) {
|
|
293
|
+
opts.gotTimeout = opts.timeout;
|
|
294
|
+
delete opts.timeout;
|
|
295
|
+
}
|
|
296
|
+
|
|
288
297
|
return opts;
|
|
289
298
|
}
|
|
290
299
|
|
|
@@ -311,9 +320,9 @@ helpers.forEach(el => {
|
|
|
311
320
|
|
|
312
321
|
got.stream = (url, opts) => asStream(normalizeArguments(url, opts));
|
|
313
322
|
|
|
314
|
-
|
|
323
|
+
for (const el of helpers) {
|
|
315
324
|
got.stream[el] = (url, opts) => got.stream(url, Object.assign({}, opts, {method: el}));
|
|
316
|
-
}
|
|
325
|
+
}
|
|
317
326
|
|
|
318
327
|
function stdError(error, opts) {
|
|
319
328
|
if (error.code !== undefined) {
|
|
@@ -334,21 +343,21 @@ got.ReadError = createErrorClass('ReadError', stdError);
|
|
|
334
343
|
got.ParseError = createErrorClass('ParseError', function (e, statusCode, opts, data) {
|
|
335
344
|
stdError.call(this, e, opts);
|
|
336
345
|
this.statusCode = statusCode;
|
|
337
|
-
this.statusMessage =
|
|
346
|
+
this.statusMessage = http.STATUS_CODES[this.statusCode];
|
|
338
347
|
this.message = `${e.message} in "${urlLib.format(opts)}": \n${data.slice(0, 77)}...`;
|
|
339
348
|
});
|
|
340
349
|
|
|
341
350
|
got.HTTPError = createErrorClass('HTTPError', function (statusCode, opts) {
|
|
342
351
|
stdError.call(this, {}, opts);
|
|
343
352
|
this.statusCode = statusCode;
|
|
344
|
-
this.statusMessage =
|
|
353
|
+
this.statusMessage = http.STATUS_CODES[this.statusCode];
|
|
345
354
|
this.message = `Response code ${this.statusCode} (${this.statusMessage})`;
|
|
346
355
|
});
|
|
347
356
|
|
|
348
357
|
got.MaxRedirectsError = createErrorClass('MaxRedirectsError', function (statusCode, opts) {
|
|
349
358
|
stdError.call(this, {}, opts);
|
|
350
359
|
this.statusCode = statusCode;
|
|
351
|
-
this.statusMessage =
|
|
360
|
+
this.statusMessage = http.STATUS_CODES[this.statusCode];
|
|
352
361
|
this.message = 'Redirected 10 times. Aborting.';
|
|
353
362
|
});
|
|
354
363
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.1",
|
|
4
4
|
"description": "Simplified HTTP requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -47,24 +47,23 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"create-error-class": "^3.0.0",
|
|
49
49
|
"duplexer3": "^0.1.4",
|
|
50
|
-
"get-stream": "^
|
|
50
|
+
"get-stream": "^3.0.0",
|
|
51
51
|
"is-redirect": "^1.0.0",
|
|
52
52
|
"is-retry-allowed": "^1.0.0",
|
|
53
53
|
"is-stream": "^1.0.0",
|
|
54
54
|
"lowercase-keys": "^1.0.0",
|
|
55
|
-
"
|
|
56
|
-
"timed-out": "^
|
|
55
|
+
"safe-buffer": "^5.0.1",
|
|
56
|
+
"timed-out": "^4.0.0",
|
|
57
57
|
"unzip-response": "^2.0.1",
|
|
58
58
|
"url-parse-lax": "^1.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"ava": "^0.
|
|
61
|
+
"ava": "^0.17.0",
|
|
62
62
|
"coveralls": "^2.11.4",
|
|
63
63
|
"form-data": "^2.1.1",
|
|
64
64
|
"get-port": "^2.0.0",
|
|
65
|
-
"get-stream": "^2.3.0",
|
|
66
65
|
"into-stream": "^3.0.0",
|
|
67
|
-
"nyc": "^
|
|
66
|
+
"nyc": "^10.0.0",
|
|
68
67
|
"pem": "^1.4.4",
|
|
69
68
|
"pify": "^2.3.0",
|
|
70
69
|
"tempfile": "^1.1.1",
|
|
@@ -72,5 +71,8 @@
|
|
|
72
71
|
},
|
|
73
72
|
"xo": {
|
|
74
73
|
"esnext": true
|
|
74
|
+
},
|
|
75
|
+
"ava": {
|
|
76
|
+
"concurrency": 4
|
|
75
77
|
}
|
|
76
78
|
}
|
package/readme.md
CHANGED
|
@@ -110,10 +110,12 @@ Query string object that will be added to the request URL. This will override th
|
|
|
110
110
|
|
|
111
111
|
###### timeout
|
|
112
112
|
|
|
113
|
-
Type: `number`
|
|
113
|
+
Type: `number`, `object`
|
|
114
114
|
|
|
115
115
|
Milliseconds to wait for a server to send response headers before aborting request with `ETIMEDOUT` error.
|
|
116
116
|
|
|
117
|
+
Option accepts `object` with separate `connect` and `socket` fields for connection and socket inactivity timeouts.
|
|
118
|
+
|
|
117
119
|
###### retries
|
|
118
120
|
|
|
119
121
|
Type: `number`, `function`<br>
|