diff --git a/source/core/index.ts b/source/core/index.ts index a96d8035a..084d0a3b0 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -31,7 +31,7 @@ import normalizePromiseArguments from '../as-promise/normalize-arguments'; import {PromiseOnly} from '../as-promise/types'; import calculateRetryDelay from './calculate-retry-delay'; -const globalDnsCache = new CacheableLookup(); +let globalDnsCache: CacheableLookup; type HttpRequestFunction = typeof httpRequest; type Error = NodeJS.ErrnoException; @@ -1762,6 +1762,10 @@ export default class Request extends Duplex implements RequestEvents { // `options.dnsCache` if (options.dnsCache === true) { + if (!globalDnsCache) { + globalDnsCache = 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)}`);