got 11.5.1 → 11.6.2
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/dist/source/as-promise/create-rejection.d.ts +0 -0
- package/dist/source/as-promise/create-rejection.js +0 -0
- package/dist/source/as-promise/index.d.ts +1 -3
- package/dist/source/as-promise/index.js +44 -125
- package/dist/source/as-promise/normalize-arguments.d.ts +3 -0
- package/dist/source/as-promise/normalize-arguments.js +78 -0
- package/dist/source/as-promise/parse-body.d.ts +3 -0
- package/dist/source/as-promise/parse-body.js +25 -0
- package/dist/source/as-promise/types.d.ts +206 -24
- package/dist/source/as-promise/types.js +18 -7
- package/dist/source/{as-promise → core}/calculate-retry-delay.d.ts +2 -1
- package/dist/source/core/calculate-retry-delay.js +29 -0
- package/dist/source/core/index.d.ts +822 -5
- package/dist/source/core/index.js +234 -46
- package/dist/source/core/utils/dns-ip-version.d.ts +0 -0
- package/dist/source/core/utils/dns-ip-version.js +0 -0
- package/dist/source/core/utils/get-body-size.d.ts +0 -0
- package/dist/source/core/utils/get-body-size.js +0 -0
- package/dist/source/core/utils/get-buffer.d.ts +0 -0
- package/dist/source/core/utils/get-buffer.js +0 -0
- package/dist/source/core/utils/is-form-data.d.ts +0 -0
- package/dist/source/core/utils/is-form-data.js +0 -0
- package/dist/source/core/utils/is-response-ok.d.ts +2 -0
- package/dist/source/core/utils/is-response-ok.js +8 -0
- package/dist/source/core/utils/options-to-url.d.ts +0 -0
- package/dist/source/core/utils/options-to-url.js +0 -0
- package/dist/source/core/utils/proxy-events.d.ts +0 -0
- package/dist/source/core/utils/proxy-events.js +0 -0
- package/dist/source/core/utils/timed-out.d.ts +0 -0
- package/dist/source/core/utils/timed-out.js +0 -0
- package/dist/source/core/utils/unhandle.d.ts +0 -0
- package/dist/source/core/utils/unhandle.js +0 -0
- package/dist/source/core/utils/url-to-options.d.ts +0 -0
- package/dist/source/core/utils/url-to-options.js +0 -0
- package/dist/source/core/utils/weakable-map.d.ts +0 -0
- package/dist/source/core/utils/weakable-map.js +0 -0
- package/dist/source/create.d.ts +0 -0
- package/dist/source/create.js +22 -14
- package/dist/source/index.d.ts +0 -0
- package/dist/source/index.js +3 -2
- package/dist/source/types.d.ts +240 -1
- package/dist/source/types.js +0 -0
- package/dist/source/utils/deep-freeze.d.ts +0 -0
- package/dist/source/utils/deep-freeze.js +0 -0
- package/dist/source/utils/deprecation-warning.d.ts +0 -0
- package/dist/source/utils/deprecation-warning.js +0 -0
- package/license +0 -0
- package/package.json +20 -16
- package/readme.md +180 -40
- package/dist/source/as-promise/calculate-retry-delay.js +0 -38
- package/dist/source/as-promise/core.d.ts +0 -13
- package/dist/source/as-promise/core.js +0 -127
package/readme.md
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
<br>
|
|
6
6
|
<br>
|
|
7
7
|
<br>
|
|
8
|
-
<p align="center">Huge thanks to <a href="https://moxy.studio"><img src="https://sindresorhus.com/assets/thanks/moxy-logo.svg" width="150"></a> for sponsoring Sindre Sorhus!
|
|
8
|
+
<p align="center">Huge thanks to <a href="https://moxy.studio"><img src="https://sindresorhus.com/assets/thanks/moxy-logo.svg" valign="middle" width="150"></a> for sponsoring Sindre Sorhus!
|
|
9
9
|
</p>
|
|
10
|
+
<p align="center"><sup>(they love Got too!)</sup></p>
|
|
10
11
|
<br>
|
|
11
12
|
<br>
|
|
12
13
|
</div>
|
|
@@ -40,7 +41,7 @@ For browser usage, we recommend [Ky](https://github.com/sindresorhus/ky) by the
|
|
|
40
41
|
- [Errors with metadata](#errors)
|
|
41
42
|
- [JSON mode](#json-mode)
|
|
42
43
|
- [WHATWG URL support](#url)
|
|
43
|
-
- [HTTPS API](#https)
|
|
44
|
+
- [HTTPS API](#advanced-https-api)
|
|
44
45
|
- [Hooks](#hooks)
|
|
45
46
|
- [Instances with custom defaults](#instances)
|
|
46
47
|
- [Types](#types)
|
|
@@ -48,6 +49,7 @@ For browser usage, we recommend [Ky](https://github.com/sindresorhus/ky) by the
|
|
|
48
49
|
- [Plugins](documentation/lets-make-a-plugin.md)
|
|
49
50
|
- [Used by 4K+ packages and 1.8M+ repos](https://github.com/sindresorhus/got/network/dependents)
|
|
50
51
|
- [Actively maintained](https://github.com/sindresorhus/got/graphs/contributors)
|
|
52
|
+
- [Trusted by many companies](#widely-used)
|
|
51
53
|
|
|
52
54
|
## Install
|
|
53
55
|
|
|
@@ -510,15 +512,15 @@ Default:
|
|
|
510
512
|
|
|
511
513
|
An object representing `limit`, `calculateDelay`, `methods`, `statusCodes`, `maxRetryAfter` and `errorCodes` fields for maximum retry count, retry handler, allowed methods, allowed status codes, maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time and allowed error codes.
|
|
512
514
|
|
|
513
|
-
**Note:** When using streams, this option is ignored. If the connection is reset when downloading, you need to catch the error and clear the file you were writing into to prevent duplicated content.
|
|
514
|
-
|
|
515
515
|
If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`.\
|
|
516
516
|
If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.
|
|
517
517
|
|
|
518
|
-
Delays between retries counts with function `1000 * Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 1).
|
|
518
|
+
Delays between retries counts with function `1000 * Math.pow(2, retry - 1) + Math.random() * 100`, where `retry` is attempt number (starts from 1).
|
|
519
519
|
|
|
520
520
|
The `calculateDelay` property is a `function` that receives an object with `attemptCount`, `retryOptions`, `error` and `computedValue` properties for current retry count, the retry options, error and default computed value. The function must return a delay in milliseconds (or a Promise resolving with it) (`0` return value cancels retry).
|
|
521
521
|
|
|
522
|
+
**Note:** The `calculateDelay` function is responsible for the entire cache mechanism, including the `limit` property. To support it, you need to check whether `computedValue` is different than `0`.
|
|
523
|
+
|
|
522
524
|
By default, it retries *only* on the specified methods, status codes, and on these network errors:
|
|
523
525
|
- `ETIMEDOUT`: One of the [timeout](#timeout) limits were reached.
|
|
524
526
|
- `ECONNRESET`: Connection was forcibly closed by a peer.
|
|
@@ -529,6 +531,36 @@ By default, it retries *only* on the specified methods, status codes, and on the
|
|
|
529
531
|
- `ENETUNREACH`: No internet connection.
|
|
530
532
|
- `EAI_AGAIN`: DNS lookup timed out.
|
|
531
533
|
|
|
534
|
+
<a name="retry-stream"></a>
|
|
535
|
+
|
|
536
|
+
You can retry Got streams too. The implementation looks like this:
|
|
537
|
+
|
|
538
|
+
```js
|
|
539
|
+
const got = require('got');
|
|
540
|
+
const fs = require('fs');
|
|
541
|
+
|
|
542
|
+
let writeStream;
|
|
543
|
+
|
|
544
|
+
const fn = (retryCount = 0) => {
|
|
545
|
+
const stream = got.stream('https://example.com');
|
|
546
|
+
stream.retryCount = retryCount;
|
|
547
|
+
|
|
548
|
+
if (writeStream) {
|
|
549
|
+
writeStream.destroy();
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
writeStream = fs.createWriteStream('example.com');
|
|
553
|
+
|
|
554
|
+
stream.pipe(writeStream);
|
|
555
|
+
|
|
556
|
+
// If you don't attach the listener, it will NOT make a retry.
|
|
557
|
+
// It automatically checks the listener count so it knows whether to retry or not :)
|
|
558
|
+
stream.once('retry', fn);
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
fn();
|
|
562
|
+
```
|
|
563
|
+
|
|
532
564
|
###### followRedirect
|
|
533
565
|
|
|
534
566
|
Type: `boolean`\
|
|
@@ -579,6 +611,13 @@ Default: `false`
|
|
|
579
611
|
|
|
580
612
|
[Cache adapter instance](#cache-adapters) for storing cached response data.
|
|
581
613
|
|
|
614
|
+
###### cacheOptions
|
|
615
|
+
|
|
616
|
+
Type: `object | undefined`\
|
|
617
|
+
Default: `{}`
|
|
618
|
+
|
|
619
|
+
[Cache options](https://github.com/kornelski/http-cache-semantics#constructor-options) used for the specified request.
|
|
620
|
+
|
|
582
621
|
###### dnsCache
|
|
583
622
|
|
|
584
623
|
Type: `CacheableLookup | false`\
|
|
@@ -689,7 +728,7 @@ Called with plain [request options](#options), right before their normalization.
|
|
|
689
728
|
See the [Request migration guide](documentation/migration-guides.md#breaking-changes) for an example.
|
|
690
729
|
|
|
691
730
|
**Note #1:** This hook must be synchronous!\
|
|
692
|
-
**Note #2:** Errors in this hook will be converted into an instances of [`RequestError`](#
|
|
731
|
+
**Note #2:** Errors in this hook will be converted into an instances of [`RequestError`](#gotrequesterror).\
|
|
693
732
|
**Note #3:** The options object may not have a `url` property. To modify it, use a `beforeRequest` hook instead.
|
|
694
733
|
|
|
695
734
|
###### hooks.beforeRequest
|
|
@@ -699,8 +738,6 @@ Default: `[]`
|
|
|
699
738
|
|
|
700
739
|
Called with [normalized](source/core/index.ts) [request options](#options). Got will make no further changes to the request before it is sent. This is especially useful in conjunction with [`got.extend()`](#instances) when you want to create an API client that, for example, uses HMAC-signing.
|
|
701
740
|
|
|
702
|
-
See the [AWS section](#aws) for an example.
|
|
703
|
-
|
|
704
741
|
**Tip:** You can override the `request` function by returning a [`ClientRequest`-like](https://nodejs.org/api/http.html#http_class_http_clientrequest) instance or a [`IncomingMessage`-like](https://nodejs.org/api/http.html#http_class_http_incomingmessage) instance. This is very useful when creating a custom cache mechanism.
|
|
705
742
|
|
|
706
743
|
###### hooks.beforeRedirect
|
|
@@ -1252,6 +1289,13 @@ If the `content-length` header is missing, `total` will be `undefined`.
|
|
|
1252
1289
|
})();
|
|
1253
1290
|
```
|
|
1254
1291
|
|
|
1292
|
+
##### .once('retry', retryCount, error)
|
|
1293
|
+
|
|
1294
|
+
To enable retrying on a Got stream, it is required to have a `retry` handler attached.\
|
|
1295
|
+
When this event is emitted, you should reset the stream you were writing to and prepare the body again.
|
|
1296
|
+
|
|
1297
|
+
See the [`retry`](#retry-stream) option for an example implementation.
|
|
1298
|
+
|
|
1255
1299
|
##### .ip
|
|
1256
1300
|
|
|
1257
1301
|
Type: `string`
|
|
@@ -1278,7 +1322,7 @@ The same as `response.socket`.
|
|
|
1278
1322
|
|
|
1279
1323
|
##### .on('error', error)
|
|
1280
1324
|
|
|
1281
|
-
The emitted `error` is an instance of [`RequestError`](#
|
|
1325
|
+
The emitted `error` is an instance of [`RequestError`](#gotrequesterror).
|
|
1282
1326
|
|
|
1283
1327
|
#### Pagination
|
|
1284
1328
|
|
|
@@ -1576,7 +1620,7 @@ Additionaly, the errors may have `request` (Got Stream) and `response` (Got Resp
|
|
|
1576
1620
|
|
|
1577
1621
|
#### got.RequestError
|
|
1578
1622
|
|
|
1579
|
-
When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`.
|
|
1623
|
+
When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`. All the errors below inherit this one.
|
|
1580
1624
|
|
|
1581
1625
|
#### got.CacheError
|
|
1582
1626
|
|
|
@@ -1612,7 +1656,7 @@ When the request is aborted due to a [timeout](#timeout). Includes an `event` an
|
|
|
1612
1656
|
|
|
1613
1657
|
#### got.CancelError
|
|
1614
1658
|
|
|
1615
|
-
When the request is aborted with `.cancel()`.
|
|
1659
|
+
When the request is aborted with `.cancel()`.
|
|
1616
1660
|
|
|
1617
1661
|
## Aborting the request
|
|
1618
1662
|
|
|
@@ -1750,6 +1794,26 @@ got('https://sindresorhus.com', {
|
|
|
1750
1794
|
});
|
|
1751
1795
|
```
|
|
1752
1796
|
|
|
1797
|
+
Otherwise, you can use the [`hpagent`](https://github.com/delvedor/hpagent) package, which keeps the internal sockets alive to be reused.
|
|
1798
|
+
|
|
1799
|
+
```js
|
|
1800
|
+
const got = require('got');
|
|
1801
|
+
const {HttpsProxyAgent} = require('hpagent');
|
|
1802
|
+
|
|
1803
|
+
got('https://sindresorhus.com', {
|
|
1804
|
+
agent: {
|
|
1805
|
+
https: new HttpsProxyAgent({
|
|
1806
|
+
keepAlive: true,
|
|
1807
|
+
keepAliveMsecs: 1000,
|
|
1808
|
+
maxSockets: 256,
|
|
1809
|
+
maxFreeSockets: 256,
|
|
1810
|
+
scheduling: 'lifo',
|
|
1811
|
+
proxy: 'https://localhost:8080'
|
|
1812
|
+
})
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
```
|
|
1816
|
+
|
|
1753
1817
|
Alternatively, use [`global-agent`](https://github.com/gajus/global-agent) to configure a global proxy for all HTTP/HTTPS traffic in your program.
|
|
1754
1818
|
|
|
1755
1819
|
Read the [`http2-wrapper`](https://github.com/szmarczak/http2-wrapper/#proxy-support) docs to learn about proxying for HTTP/2.
|
|
@@ -1840,29 +1904,14 @@ got('unix:/var/run/docker.sock:/containers/json');
|
|
|
1840
1904
|
|
|
1841
1905
|
## AWS
|
|
1842
1906
|
|
|
1843
|
-
Requests to AWS services need to have their headers signed. This can be accomplished by using the [`
|
|
1907
|
+
Requests to AWS services need to have their headers signed. This can be accomplished by using the [`got4aws`](https://www.npmjs.com/package/got4aws) package. This is an example for querying an ["API Gateway"](https://docs.aws.amazon.com/apigateway/api-reference/signing-requests/) with a signed request.
|
|
1844
1908
|
|
|
1845
1909
|
```js
|
|
1846
|
-
const
|
|
1847
|
-
const AWS = require('aws-sdk');
|
|
1848
|
-
const aws4 = require('aws4');
|
|
1910
|
+
const got4aws = require('got4aws');;
|
|
1849
1911
|
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
// Create a Got instance to use relative paths and signed requests
|
|
1853
|
-
const awsClient = got.extend({
|
|
1854
|
-
prefixUrl: 'https://<api-id>.execute-api.<api-region>.amazonaws.com/<stage>/',
|
|
1855
|
-
hooks: {
|
|
1856
|
-
beforeRequest: [
|
|
1857
|
-
async options => {
|
|
1858
|
-
const credentials = await chain.resolvePromise();
|
|
1859
|
-
aws4.sign(options, credentials);
|
|
1860
|
-
}
|
|
1861
|
-
]
|
|
1862
|
-
}
|
|
1863
|
-
});
|
|
1912
|
+
const awsClient = got4aws();
|
|
1864
1913
|
|
|
1865
|
-
const response = await awsClient('endpoint/path', {
|
|
1914
|
+
const response = await awsClient('https://<api-id>.execute-api.<api-region>.amazonaws.com/<stage>/endpoint/path', {
|
|
1866
1915
|
// Request-specific options
|
|
1867
1916
|
});
|
|
1868
1917
|
```
|
|
@@ -1886,6 +1935,32 @@ nock('https://sindresorhus.com')
|
|
|
1886
1935
|
})();
|
|
1887
1936
|
```
|
|
1888
1937
|
|
|
1938
|
+
Bear in mind, that by default `nock` mocks only one request. Got will [retry](#retry) on failed requests by default, causing a `No match for request ...` error. The solution is to either disable retrying (set `options.retry` to `0`) or call `.persist()` on the mocked request.
|
|
1939
|
+
|
|
1940
|
+
```js
|
|
1941
|
+
const got = require('got');
|
|
1942
|
+
const nock = require('nock');
|
|
1943
|
+
|
|
1944
|
+
const scope = nock('https://sindresorhus.com')
|
|
1945
|
+
.get('/')
|
|
1946
|
+
.reply(500, 'Internal server error')
|
|
1947
|
+
.persist();
|
|
1948
|
+
|
|
1949
|
+
(async () => {
|
|
1950
|
+
try {
|
|
1951
|
+
await got('https://sindresorhus.com')
|
|
1952
|
+
} catch (error) {
|
|
1953
|
+
console.log(error.response.body);
|
|
1954
|
+
//=> 'Internal server error'
|
|
1955
|
+
|
|
1956
|
+
console.log(error.response.retryCount);
|
|
1957
|
+
//=> 2
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
scope.persist(false);
|
|
1961
|
+
})();
|
|
1962
|
+
```
|
|
1963
|
+
|
|
1889
1964
|
For real integration testing we recommend using [`ava`](https://github.com/avajs/ava) with [`create-test-server`](https://github.com/lukechilds/create-test-server). We're using a macro so we don't have to `server.listen()` and `server.close()` every test. Take a look at one of our tests:
|
|
1890
1965
|
|
|
1891
1966
|
```js
|
|
@@ -2043,7 +2118,7 @@ The Electron `net` module is not consistent with the Node.js `http` module. See
|
|
|
2043
2118
|
\* It's almost API compatible with the browser `fetch` API.\
|
|
2044
2119
|
\*\* Need to switch the protocol manually. Doesn't accept PUSH streams and doesn't reuse HTTP/2 sessions.\
|
|
2045
2120
|
\*\*\* Currently, only `DownloadProgress` event is supported, `UploadProgress` event is not supported.\
|
|
2046
|
-
:sparkle: Almost-stable feature, but the API may change. Don't
|
|
2121
|
+
:sparkle: Almost-stable feature, but the API may change. Don't hesitate to try it out!\
|
|
2047
2122
|
:grey_question: Feature in early stage of development. Very experimental.
|
|
2048
2123
|
|
|
2049
2124
|
<!-- GITHUB -->
|
|
@@ -2121,12 +2196,12 @@ The Electron `net` module is not consistent with the Node.js `http` module. See
|
|
|
2121
2196
|
[ab]: https://badgen.net/travis/axios/axios?label
|
|
2122
2197
|
[sb]: https://badgen.net/travis/visionmedia/superagent?label
|
|
2123
2198
|
|
|
2124
|
-
[g5]: https://travis-ci.
|
|
2125
|
-
[k5]: https://travis-ci.
|
|
2126
|
-
[r5]: https://travis-ci.org/request/request
|
|
2127
|
-
[n5]: https://travis-ci.org/bitinn/node-fetch
|
|
2128
|
-
[a5]: https://travis-ci.org/axios/axios
|
|
2129
|
-
[s5]: https://travis-ci.org/visionmedia/superagent
|
|
2199
|
+
[g5]: https://travis-ci.com/github/sindresorhus/got
|
|
2200
|
+
[k5]: https://travis-ci.com/github/sindresorhus/ky
|
|
2201
|
+
[r5]: https://travis-ci.org/github/request/request
|
|
2202
|
+
[n5]: https://travis-ci.org/github/bitinn/node-fetch
|
|
2203
|
+
[a5]: https://travis-ci.org/github/axios/axios
|
|
2204
|
+
[s5]: https://travis-ci.org/github/visionmedia/superagent
|
|
2130
2205
|
|
|
2131
2206
|
<!-- BUGS -->
|
|
2132
2207
|
[gbg]: https://badgen.net/github/label-issues/sindresorhus/got/bug/open?label
|
|
@@ -2233,9 +2308,9 @@ The Electron `net` module is not consistent with the Node.js `http` module. See
|
|
|
2233
2308
|
|
|
2234
2309
|
## Maintainers
|
|
2235
2310
|
|
|
2236
|
-
[](https://sindresorhus.com) | [](https://github.com/szmarczak)
|
|
2237
|
-
|
|
2238
|
-
[Sindre Sorhus](https://sindresorhus.com) | [Szymon Marczak](https://github.com/szmarczak)
|
|
2311
|
+
[](https://sindresorhus.com) | [](https://github.com/szmarczak) | [](https://github.com/Giotino)
|
|
2312
|
+
---|---|---
|
|
2313
|
+
[Sindre Sorhus](https://sindresorhus.com) | [Szymon Marczak](https://github.com/szmarczak) | [Giovanni Minotti](https://github.com/Giotino)
|
|
2239
2314
|
|
|
2240
2315
|
###### Former
|
|
2241
2316
|
|
|
@@ -2244,6 +2319,71 @@ The Electron `net` module is not consistent with the Node.js `http` module. See
|
|
|
2244
2319
|
- [Brandon Smith](https://github.com/brandon93s)
|
|
2245
2320
|
- [Luke Childs](https://github.com/lukechilds)
|
|
2246
2321
|
|
|
2322
|
+
<a name="widely-used"></a>
|
|
2323
|
+
## These amazing companies are using Got
|
|
2324
|
+
|
|
2325
|
+
<a href="https://segment.com"><img width="90" valign="middle" src="https://user-images.githubusercontent.com/697676/47693700-ddb62500-dbb7-11e8-8332-716a91010c2d.png"></a>
|
|
2326
|
+
|
|
2327
|
+
<a href="https://antora.org"><img width="100" valign="middle" src="https://user-images.githubusercontent.com/79351/47706840-d874cc80-dbef-11e8-87c6-5f0c60cbf5dc.png"></a>
|
|
2328
|
+
|
|
2329
|
+
<a href="https://getvoip.com"><img width="150" valign="middle" src="https://user-images.githubusercontent.com/10832620/47869404-429e9480-dddd-11e8-8a7a-ca43d7f06020.png"></a>
|
|
2330
|
+
|
|
2331
|
+
<a href="https://github.com/exoframejs/exoframe"><img width="150" valign="middle" src="https://user-images.githubusercontent.com/365944/47791460-11a95b80-dd1a-11e8-9070-e8f2a215e03a.png"></a>
|
|
2332
|
+
|
|
2333
|
+
<a href="http://karaokes.moe"><img width="140" valign="middle" src="https://camo.githubusercontent.com/6860e5fa4684c14d8e1aa65df0aba4e6808ea1a9/687474703a2f2f6b6172616f6b65732e6d6f652f6173736574732f696d616765732f696e6465782e706e67"></a>
|
|
2334
|
+
|
|
2335
|
+
<a href="https://github.com/renovatebot/renovate"><img width="150" valign="middle" src="https://camo.githubusercontent.com/206d470ac709b9a702a97b0c08d6f389a086793d/68747470733a2f2f72656e6f76617465626f742e636f6d2f696d616765732f6c6f676f2e737667"></a>
|
|
2336
|
+
|
|
2337
|
+
<a href="https://resist.bot"><img width="150" valign="middle" src="https://user-images.githubusercontent.com/3322287/51992724-28736180-2473-11e9-9764-599cfda4b012.png"></a>
|
|
2338
|
+
|
|
2339
|
+
<a href="https://www.naturalcycles.com"><img width="150" valign="middle" src="https://user-images.githubusercontent.com/170270/92244143-d0a8a200-eec2-11ea-9fc0-1c07f90b2113.png"></a>
|
|
2340
|
+
|
|
2341
|
+
<a href="https://microlink.io"><img width="150" valign="middle" src="https://user-images.githubusercontent.com/36894700/91992974-1cc5dc00-ed35-11ea-9d04-f58b42ce6a5e.png"></a>
|
|
2342
|
+
|
|
2343
|
+
<a href="https://radity.com"><img width="150" valign="middle" src="https://user-images.githubusercontent.com/29518613/91814036-97fb9500-ec44-11ea-8c6c-d198cc23ca29.png"></a>
|
|
2344
|
+
|
|
2345
|
+
<br>
|
|
2346
|
+
|
|
2347
|
+
> Segment is a happy user of Got! Got powers the main backend API that our app talks to. It's used by our in-house RPC client that we use to communicate with all microservices.
|
|
2348
|
+
>
|
|
2349
|
+
> — <a href="https://github.com/vadimdemedes">Vadim Demedes</a>
|
|
2350
|
+
|
|
2351
|
+
> Antora, a static site generator for creating documentation sites, uses Got to download the UI bundle. In Antora, the UI bundle (aka theme) is maintained as a separate project. That project exports the UI as a zip file we call the UI bundle. The main site generator downloads that UI from a URL using Got and streams it to vinyl-zip to extract the files. Those files go on to be used to create the HTML pages and supporting assets.
|
|
2352
|
+
>
|
|
2353
|
+
> — <a href="https://github.com/mojavelinux">Dan Allen</a>
|
|
2354
|
+
|
|
2355
|
+
> GetVoIP is happily using Got in production. One of the unique capabilities of Got is the ability to handle Unix sockets which enables us to build a full control interfaces for our docker stack.
|
|
2356
|
+
>
|
|
2357
|
+
> — <a href="https://github.com/danielkalen">Daniel Kalen</a>
|
|
2358
|
+
|
|
2359
|
+
> We're using Got inside of Exoframe to handle all the communication between CLI and server. Exoframe is a self-hosted tool that allows simple one-command deployments using Docker.
|
|
2360
|
+
>
|
|
2361
|
+
> — <a href="https://github.com/yamalight">Tim Ermilov</a>
|
|
2362
|
+
|
|
2363
|
+
> Karaoke Mugen uses Got to fetch content updates from its online server.
|
|
2364
|
+
>
|
|
2365
|
+
> — <a href="https://github.com/AxelTerizaki">Axel Terizaki</a>
|
|
2366
|
+
|
|
2367
|
+
> Renovate uses Got, gh-got and gl-got to send millions of queries per day to GitHub, GitLab, npmjs, PyPi, Packagist, Docker Hub, Terraform, CircleCI, and more.
|
|
2368
|
+
>
|
|
2369
|
+
> — <a href="https://github.com/rarkins">Rhys Arkins</a>
|
|
2370
|
+
|
|
2371
|
+
> Resistbot uses Got to communicate from the API frontend where all correspondence ingresses to the officials lookup database in back.
|
|
2372
|
+
>
|
|
2373
|
+
> — <a href="https://github.com/chris-erickson">Chris Erickson</a>
|
|
2374
|
+
|
|
2375
|
+
> Natural Cycles is using Got to communicate with all kinds of 3rd-party REST APIs (over 9000!).
|
|
2376
|
+
>
|
|
2377
|
+
> — <a href="https://github.com/kirillgroshkov">Kirill Groshkov</a>
|
|
2378
|
+
|
|
2379
|
+
> Microlink is a cloud browser as an API service that uses Got widely as the main HTTP client, serving ~22M requests a month, every time a network call needs to be performed.
|
|
2380
|
+
>
|
|
2381
|
+
> — <a href="https://github.com/Kikobeats">Kiko Beats</a>
|
|
2382
|
+
|
|
2383
|
+
> We’re using Got at Radity. Thanks for such an amazing work!
|
|
2384
|
+
>
|
|
2385
|
+
> — <a href="https://github.com/MirzayevFarid">Mirzayev Farid</a>
|
|
2386
|
+
|
|
2247
2387
|
## For enterprise
|
|
2248
2388
|
|
|
2249
2389
|
Available as part of the Tidelift Subscription.
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const types_1 = require("./types");
|
|
4
|
-
const retryAfterStatusCodes = new Set([413, 429, 503]);
|
|
5
|
-
const isErrorWithResponse = (error) => (error instanceof types_1.HTTPError || error instanceof types_1.ParseError || error instanceof types_1.MaxRedirectsError);
|
|
6
|
-
const calculateRetryDelay = ({ attemptCount, retryOptions, error }) => {
|
|
7
|
-
if (attemptCount > retryOptions.limit) {
|
|
8
|
-
return 0;
|
|
9
|
-
}
|
|
10
|
-
const hasMethod = retryOptions.methods.includes(error.options.method);
|
|
11
|
-
const hasErrorCode = retryOptions.errorCodes.includes(error.code);
|
|
12
|
-
const hasStatusCode = isErrorWithResponse(error) && retryOptions.statusCodes.includes(error.response.statusCode);
|
|
13
|
-
if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
if (isErrorWithResponse(error)) {
|
|
17
|
-
const { response } = error;
|
|
18
|
-
if (response && 'retry-after' in response.headers && retryAfterStatusCodes.has(response.statusCode)) {
|
|
19
|
-
let after = Number(response.headers['retry-after']);
|
|
20
|
-
if (Number.isNaN(after)) {
|
|
21
|
-
after = Date.parse(response.headers['retry-after']) - Date.now();
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
after *= 1000;
|
|
25
|
-
}
|
|
26
|
-
if (retryOptions.maxRetryAfter === undefined || after > retryOptions.maxRetryAfter) {
|
|
27
|
-
return 0;
|
|
28
|
-
}
|
|
29
|
-
return after;
|
|
30
|
-
}
|
|
31
|
-
if (response.statusCode === 413) {
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const noise = Math.random() * 100;
|
|
36
|
-
return ((2 ** (attemptCount - 1)) * 1000) + noise;
|
|
37
|
-
};
|
|
38
|
-
exports.default = calculateRetryDelay;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { URL } from 'url';
|
|
3
|
-
import { Options, NormalizedOptions, Defaults, ResponseType, Response } from './types';
|
|
4
|
-
import Request, { ParseJsonFunction } from '../core';
|
|
5
|
-
export declare const knownBodyTypes: string[];
|
|
6
|
-
export declare const parseBody: (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined) => unknown;
|
|
7
|
-
export default class PromisableRequest extends Request {
|
|
8
|
-
['constructor']: typeof PromisableRequest;
|
|
9
|
-
options: NormalizedOptions;
|
|
10
|
-
static normalizeArguments(url?: string | URL, nonNormalizedOptions?: Options, defaults?: Defaults): NormalizedOptions;
|
|
11
|
-
static mergeOptions(...sources: Options[]): NormalizedOptions;
|
|
12
|
-
_beforeError(error: Error): void;
|
|
13
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseBody = exports.knownBodyTypes = void 0;
|
|
4
|
-
const is_1 = require("@sindresorhus/is");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
const core_1 = require("../core");
|
|
7
|
-
if (!core_1.knownHookEvents.includes('beforeRetry')) {
|
|
8
|
-
core_1.knownHookEvents.push('beforeRetry', 'afterResponse');
|
|
9
|
-
}
|
|
10
|
-
exports.knownBodyTypes = ['json', 'buffer', 'text'];
|
|
11
|
-
exports.parseBody = (response, responseType, parseJson, encoding) => {
|
|
12
|
-
const { rawBody } = response;
|
|
13
|
-
try {
|
|
14
|
-
if (responseType === 'text') {
|
|
15
|
-
return rawBody.toString(encoding);
|
|
16
|
-
}
|
|
17
|
-
if (responseType === 'json') {
|
|
18
|
-
return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
|
|
19
|
-
}
|
|
20
|
-
if (responseType === 'buffer') {
|
|
21
|
-
return Buffer.from(rawBody);
|
|
22
|
-
}
|
|
23
|
-
throw new types_1.ParseError({
|
|
24
|
-
message: `Unknown body type '${responseType}'`,
|
|
25
|
-
name: 'Error'
|
|
26
|
-
}, response);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
throw new types_1.ParseError(error, response);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
class PromisableRequest extends core_1.default {
|
|
33
|
-
static normalizeArguments(url, nonNormalizedOptions, defaults) {
|
|
34
|
-
const options = super.normalizeArguments(url, nonNormalizedOptions, defaults);
|
|
35
|
-
if (is_1.default.null_(options.encoding)) {
|
|
36
|
-
throw new TypeError('To get a Buffer, set `options.responseType` to `buffer` instead');
|
|
37
|
-
}
|
|
38
|
-
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.encoding);
|
|
39
|
-
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.resolveBodyOnly);
|
|
40
|
-
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.methodRewriting);
|
|
41
|
-
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.isStream);
|
|
42
|
-
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.responseType);
|
|
43
|
-
// `options.responseType`
|
|
44
|
-
if (options.responseType === undefined) {
|
|
45
|
-
options.responseType = 'text';
|
|
46
|
-
}
|
|
47
|
-
// `options.retry`
|
|
48
|
-
const { retry } = options;
|
|
49
|
-
if (defaults) {
|
|
50
|
-
options.retry = { ...defaults.retry };
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
options.retry = {
|
|
54
|
-
calculateDelay: retryObject => retryObject.computedValue,
|
|
55
|
-
limit: 0,
|
|
56
|
-
methods: [],
|
|
57
|
-
statusCodes: [],
|
|
58
|
-
errorCodes: [],
|
|
59
|
-
maxRetryAfter: undefined
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (is_1.default.object(retry)) {
|
|
63
|
-
options.retry = {
|
|
64
|
-
...options.retry,
|
|
65
|
-
...retry
|
|
66
|
-
};
|
|
67
|
-
options.retry.methods = [...new Set(options.retry.methods.map(method => method.toUpperCase()))];
|
|
68
|
-
options.retry.statusCodes = [...new Set(options.retry.statusCodes)];
|
|
69
|
-
options.retry.errorCodes = [...new Set(options.retry.errorCodes)];
|
|
70
|
-
}
|
|
71
|
-
else if (is_1.default.number(retry)) {
|
|
72
|
-
options.retry.limit = retry;
|
|
73
|
-
}
|
|
74
|
-
if (is_1.default.undefined(options.retry.maxRetryAfter)) {
|
|
75
|
-
options.retry.maxRetryAfter = Math.min(
|
|
76
|
-
// TypeScript is not smart enough to handle `.filter(x => is.number(x))`.
|
|
77
|
-
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
|
|
78
|
-
...[options.timeout.request, options.timeout.connect].filter(is_1.default.number));
|
|
79
|
-
}
|
|
80
|
-
// `options.pagination`
|
|
81
|
-
if (is_1.default.object(options.pagination)) {
|
|
82
|
-
if (defaults) {
|
|
83
|
-
options.pagination = {
|
|
84
|
-
...defaults.pagination,
|
|
85
|
-
...options.pagination
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const { pagination } = options;
|
|
89
|
-
if (!is_1.default.function_(pagination.transform)) {
|
|
90
|
-
throw new Error('`options.pagination.transform` must be implemented');
|
|
91
|
-
}
|
|
92
|
-
if (!is_1.default.function_(pagination.shouldContinue)) {
|
|
93
|
-
throw new Error('`options.pagination.shouldContinue` must be implemented');
|
|
94
|
-
}
|
|
95
|
-
if (!is_1.default.function_(pagination.filter)) {
|
|
96
|
-
throw new TypeError('`options.pagination.filter` must be implemented');
|
|
97
|
-
}
|
|
98
|
-
if (!is_1.default.function_(pagination.paginate)) {
|
|
99
|
-
throw new Error('`options.pagination.paginate` must be implemented');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// JSON mode
|
|
103
|
-
if (options.responseType === 'json' && options.headers.accept === undefined) {
|
|
104
|
-
options.headers.accept = 'application/json';
|
|
105
|
-
}
|
|
106
|
-
return options;
|
|
107
|
-
}
|
|
108
|
-
static mergeOptions(...sources) {
|
|
109
|
-
let mergedOptions;
|
|
110
|
-
for (const source of sources) {
|
|
111
|
-
mergedOptions = PromisableRequest.normalizeArguments(undefined, source, mergedOptions);
|
|
112
|
-
}
|
|
113
|
-
return mergedOptions;
|
|
114
|
-
}
|
|
115
|
-
_beforeError(error) {
|
|
116
|
-
if (this.destroyed) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (!(error instanceof core_1.RequestError)) {
|
|
120
|
-
error = new core_1.RequestError(error.message, error, this);
|
|
121
|
-
}
|
|
122
|
-
// Let the promise decide whether to abort or not
|
|
123
|
-
// It is also responsible for the `beforeError` hook
|
|
124
|
-
this.emit('error', error);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.default = PromisableRequest;
|