Skip to content

Commit 79507c2

Browse files
committed
Disable options.dnsCache by default
1 parent 05ff878 commit 79507c2

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,13 @@ Default: `false`
481481

482482
###### dnsCache
483483

484-
Type: `object | false`\
485-
Default: `new CacheableLookup()`
484+
Type: `CacheableLookup | false`\
485+
Default: `false`
486+
487+
An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups. Useful when making lots of requests to different *public* hostnames.
486488

487-
An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
489+
**Note:** This should stay disabled when making requests to internal hostnames such as `localhost`, `database.local` etc.\
490+
`CacheableLookup` uses `dns.resolver4(..)` and `dns.resolver6(...)` under the hood and fall backs to `dns.lookup(...)` when the first two fail, which may lead to additional delay.
488491

489492
###### request
490493

source/core/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
594594
options.cache = undefined;
595595
}
596596

597+
if (options.dnsCache === false) {
598+
options.cache = undefined;
599+
}
600+
597601
// Nice type assertions
598602
assert.any([is.string, is.undefined], options.method);
599603
assert.any([is.object, is.undefined], options.headers);

source/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {URL} from 'url';
2-
import CacheableLookup from 'cacheable-lookup';
32
import {Response, Options} from './as-promise';
43
import create, {defaultHandler, InstanceDefaults} from './create';
54

@@ -54,7 +53,7 @@ const defaults: InstanceDefaults = {
5453
afterResponse: []
5554
},
5655
cache: undefined,
57-
dnsCache: new CacheableLookup(),
56+
dnsCache: undefined,
5857
decompress: true,
5958
throwHttpErrors: true,
6059
followRedirect: true,

0 commit comments

Comments
 (0)