diff --git a/source/core/index.ts b/source/core/index.ts index f49889235..b51a6ae52 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -28,6 +28,8 @@ import {DnsLookupIpVersion, isDnsLookupIpVersion, dnsLookupIpVersionToFamily} fr import deprecationWarning from '../utils/deprecation-warning'; import {PromiseOnly} from '../as-promise/types'; +const globalDnsCache = new CacheableLookup(); + type HttpRequestFunction = typeof httpRequest; type Error = NodeJS.ErrnoException; @@ -888,7 +890,7 @@ export default class Request extends Duplex implements RequestEvents { // `options.dnsCache` if (options.dnsCache === true) { - options.dnsCache = new CacheableLookup(); + options.dnsCache = globalDnsCache; } else if (!is.undefined(options.dnsCache) && !options.dnsCache.lookup) { throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is(options.dnsCache)}`); } diff --git a/test/create.ts b/test/create.ts index d8589653f..75f47cdc1 100644 --- a/test/create.ts +++ b/test/create.ts @@ -312,3 +312,15 @@ test('async handlers can throw', async t => { await t.throwsAsync(instance('https://example.com'), {message}); }); + +test('setting dnsCache to true points to global cache', t => { + const a = got.extend({ + dnsCache: true + }); + + const b = got.extend({ + dnsCache: true + }); + + t.is(a.defaults.options.dnsCache, b.defaults.options.dnsCache); +});