got 11.7.0 → 11.8.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.
@@ -133,9 +133,10 @@ function asPromise(normalizedOptions) {
133
133
  reject(error);
134
134
  };
135
135
  request.once('error', onError);
136
+ const previousBody = request.options.body;
136
137
  request.once('retry', (newRetryCount, error) => {
137
- var _a;
138
- if (is_1.default.nodeStream((_a = error.request) === null || _a === void 0 ? void 0 : _a.options.body)) {
138
+ var _a, _b;
139
+ if (previousBody === ((_a = error.request) === null || _a === void 0 ? void 0 : _a.options.body) && is_1.default.nodeStream((_b = error.request) === null || _b === void 0 ? void 0 : _b.options.body)) {
139
140
  onError(error);
140
141
  return;
141
142
  }
@@ -41,12 +41,8 @@ export interface Agents {
41
41
  }
42
42
  export declare const withoutBody: ReadonlySet<string>;
43
43
  export interface ToughCookieJar {
44
- getCookieString: ((currentUrl: string, options: {
45
- [key: string]: unknown;
46
- }, cb: (err: Error | null, cookies: string) => void) => void) & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
47
- setCookie: ((cookieOrString: unknown, currentUrl: string, options: {
48
- [key: string]: unknown;
49
- }, cb: (err: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
44
+ getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (err: Error | null, cookies: string) => void) => void) & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
45
+ setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (err: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
50
46
  }
51
47
  export interface PromiseCookieJar {
52
48
  getCookieString: (url: string) => Promise<string>;
@@ -352,9 +348,7 @@ interface PlainOptions extends URLOptions {
352
348
 
353
349
  __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
354
350
  */
355
- form?: {
356
- [key: string]: any;
357
- };
351
+ form?: Record<string, any>;
358
352
  /**
359
353
  JSON body. If the `Content-Type` header is not set, it will be set to `application/json`.
360
354
 
@@ -362,9 +356,7 @@ interface PlainOptions extends URLOptions {
362
356
 
363
357
  __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
364
358
  */
365
- json?: {
366
- [key: string]: any;
367
- };
359
+ json?: Record<string, any>;
368
360
  /**
369
361
  The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
370
362
 
@@ -415,9 +407,7 @@ interface PlainOptions extends URLOptions {
415
407
  //=> 'key=a&key=b'
416
408
  ```
417
409
  */
418
- searchParams?: string | {
419
- [key: string]: string | number | boolean | null | undefined;
420
- } | URLSearchParams;
410
+ searchParams?: string | Record<string, string | number | boolean | null | undefined> | URLSearchParams;
421
411
  /**
422
412
  An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
423
413
  Useful when making lots of requests to different *public* hostnames.
@@ -628,7 +628,7 @@ class Request extends stream_1.Duplex {
628
628
  if (defaults && !areHooksDefault) {
629
629
  for (const event of exports.knownHookEvents) {
630
630
  const defaultHooks = defaults.hooks[event];
631
- if (defaultHooks.length !== 0) {
631
+ if (defaultHooks.length > 0) {
632
632
  // See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
633
633
  options.hooks[event] = [
634
634
  ...defaults.hooks[event],
@@ -950,12 +950,7 @@ class Request extends stream_1.Duplex {
950
950
  request.destroy();
951
951
  // Node.js <= 12.18.2 mistakenly emits the response `end` first.
952
952
  (_a = request.res) === null || _a === void 0 ? void 0 : _a.removeAllListeners('end');
953
- if (error instanceof timed_out_1.TimeoutError) {
954
- error = new TimeoutError(error, this.timings, this);
955
- }
956
- else {
957
- error = new RequestError(error.message, error, this);
958
- }
953
+ error = error instanceof timed_out_1.TimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
959
954
  this._beforeError(error);
960
955
  });
961
956
  this[kUnproxyEvents] = proxy_events_1.default(request, this, proxiedRequestEvents);
@@ -1319,7 +1314,7 @@ class Request extends stream_1.Duplex {
1319
1314
  });
1320
1315
  // TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
1321
1316
  this[kRequest].write(chunk, encoding, (error) => {
1322
- if (!error && this._progressCallbacks.length !== 0) {
1317
+ if (!error && this._progressCallbacks.length > 0) {
1323
1318
  this._progressCallbacks.shift()();
1324
1319
  }
1325
1320
  callback(error);
@@ -1383,7 +1378,7 @@ class Request extends stream_1.Duplex {
1383
1378
  */
1384
1379
  get ip() {
1385
1380
  var _a;
1386
- return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket.remoteAddress;
1381
+ return (_a = this.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress;
1387
1382
  }
1388
1383
  /**
1389
1384
  Indicates whether the request has been aborted or not.
@@ -1393,8 +1388,8 @@ class Request extends stream_1.Duplex {
1393
1388
  return ((_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroyed) !== null && _b !== void 0 ? _b : this.destroyed) && !((_c = this[kOriginalResponse]) === null || _c === void 0 ? void 0 : _c.complete);
1394
1389
  }
1395
1390
  get socket() {
1396
- var _a;
1397
- return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket;
1391
+ var _a, _b;
1392
+ return (_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket) !== null && _b !== void 0 ? _b : undefined;
1398
1393
  }
1399
1394
  /**
1400
1395
  Progress event for downloading (receiving a response).
@@ -23,6 +23,9 @@ exports.default = async (body, headers) => {
23
23
  }
24
24
  if (body instanceof fs_1.ReadStream) {
25
25
  const { size } = await statAsync(body.path);
26
+ if (size === 0) {
27
+ return undefined;
28
+ }
26
29
  return size;
27
30
  }
28
31
  return undefined;
@@ -14,7 +14,7 @@ exports.default = (url) => {
14
14
  href: url.href,
15
15
  path: `${url.pathname || ''}${url.search || ''}`
16
16
  };
17
- if (is_1.default.string(url.port) && url.port.length !== 0) {
17
+ if (is_1.default.string(url.port) && url.port.length > 0) {
18
18
  options.port = Number(url.port);
19
19
  }
20
20
  if (url.username || url.password) {
@@ -82,7 +82,7 @@ const create = (defaults) => {
82
82
  return result;
83
83
  }));
84
84
  // Got interface
85
- const got = ((url, options, _defaults) => {
85
+ const got = ((url, options = {}, _defaults) => {
86
86
  var _a, _b;
87
87
  let iteration = 0;
88
88
  const iterateHandlers = (newOptions) => {
@@ -103,7 +103,7 @@ const create = (defaults) => {
103
103
  let initHookError;
104
104
  try {
105
105
  callInitHooks(defaults.options.hooks.init, options);
106
- callInitHooks((_a = options === null || options === void 0 ? void 0 : options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
106
+ callInitHooks((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
107
107
  }
108
108
  catch (error) {
109
109
  initHookError = error;
@@ -117,11 +117,11 @@ const create = (defaults) => {
117
117
  return iterateHandlers(normalizedOptions);
118
118
  }
119
119
  catch (error) {
120
- if (options === null || options === void 0 ? void 0 : options.isStream) {
120
+ if (options.isStream) {
121
121
  throw error;
122
122
  }
123
123
  else {
124
- return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options === null || options === void 0 ? void 0 : options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
124
+ return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
125
125
  }
126
126
  }
127
127
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "11.7.0",
3
+ "version": "11.8.0",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
@@ -43,7 +43,7 @@
43
43
  "ky"
44
44
  ],
45
45
  "dependencies": {
46
- "@sindresorhus/is": "^3.1.1",
46
+ "@sindresorhus/is": "^4.0.0",
47
47
  "@szmarczak/http-timer": "^4.0.5",
48
48
  "@types/cacheable-request": "^6.0.1",
49
49
  "@types/responselike": "^1.0.0",
@@ -61,7 +61,7 @@
61
61
  "@sinonjs/fake-timers": "^6.0.1",
62
62
  "@types/benchmark": "^1.0.33",
63
63
  "@types/express": "^4.17.7",
64
- "@types/node": "^14.6.0",
64
+ "@types/node": "^14.14.0",
65
65
  "@types/node-fetch": "^2.5.7",
66
66
  "@types/pem": "^1.9.5",
67
67
  "@types/pify": "^3.0.2",
@@ -87,11 +87,11 @@
87
87
  "pify": "^5.0.0",
88
88
  "sinon": "^9.0.3",
89
89
  "slow-stream": "0.0.4",
90
- "tempy": "^0.6.0",
90
+ "tempy": "^1.0.0",
91
91
  "to-readable-stream": "^2.1.0",
92
92
  "tough-cookie": "^4.0.0",
93
- "typescript": "^4.0.2",
94
- "xo": "^0.33.0"
93
+ "typescript": "4.0.3",
94
+ "xo": "^0.34.1"
95
95
  },
96
96
  "types": "dist/source",
97
97
  "sideEffects": false,
@@ -123,7 +123,7 @@
123
123
  "node/prefer-global/url": "off",
124
124
  "node/prefer-global/url-search-params": "off",
125
125
  "import/no-anonymous-default-export": "off",
126
- "@typescript-eslint/no-invalid-void-type": "off"
126
+ "@typescript-eslint/no-implicit-any-catch": "off"
127
127
  }
128
128
  },
129
129
  "runkitExampleFilename": "./documentation/examples/runkit-example.js"
package/readme.md CHANGED
@@ -107,16 +107,16 @@ const got = require('got');
107
107
  const pipeline = promisify(stream.pipeline);
108
108
 
109
109
  (async () => {
110
- await pipeline(
111
- got.stream('https://sindresorhus.com'),
112
- fs.createWriteStream('index.html')
113
- );
114
-
115
- // For POST, PUT, and PATCH methods `got.stream` returns a `stream.Writable`
116
- await pipeline(
117
- fs.createReadStream('index.html'),
118
- got.stream.post('https://sindresorhus.com')
119
- );
110
+ await pipeline(
111
+ got.stream('https://sindresorhus.com'),
112
+ fs.createWriteStream('index.html')
113
+ );
114
+
115
+ // For POST, PUT, PATCH, and DELETE methods, `got.stream` returns a `stream.Writable`.
116
+ await pipeline(
117
+ fs.createReadStream('index.html'),
118
+ got.stream.post('https://sindresorhus.com')
119
+ );
120
120
  })();
121
121
  ```
122
122
 
@@ -306,7 +306,7 @@ Example:
306
306
  const bufferPromise = responsePromise.buffer();
307
307
  const jsonPromise = responsePromise.json();
308
308
 
309
- const [response, buffer, json] = Promise.all([responsePromise, bufferPromise, jsonPromise]);
309
+ const [response, buffer, json] = await Promise.all([responsePromise, bufferPromise, jsonPromise]);
310
310
  // `response` is an instance of Got Response
311
311
  // `buffer` is an instance of Buffer
312
312
  // `json` is an object
@@ -655,6 +655,15 @@ await got('https://api6.ipify.org', {
655
655
  });
656
656
  ```
657
657
 
658
+ ###### lookup
659
+
660
+ Type: `Function`\
661
+ Default: [`dns.lookup`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback)
662
+
663
+ Custom DNS resolution logic.
664
+
665
+ The function signature is the same as [`dns.lookup`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
666
+
658
667
  ###### request
659
668
 
660
669
  Type: `Function`\
@@ -873,12 +882,12 @@ got('https://api.github.com/some-endpoint', {
873
882
  beforeError: [
874
883
  error => {
875
884
  const {response} = error;
876
- if (response && response.body) {
885
+ if (response && response.body) {
877
886
  error.name = 'GitHubError';
878
887
  error.message = `${response.body.message} (${response.statusCode})`;
879
888
  }
880
889
 
881
- return error;
890
+ return error;
882
891
  }
883
892
  ]
884
893
  }