Skip to content

Commit

Permalink
Instantiate CacheableLookup only when needed (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
fungiboletus authored and sindresorhus committed Feb 26, 2021
1 parent a72ed84 commit 3bd245f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1762,6 +1762,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {

// `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)}`);
Expand Down

0 comments on commit 3bd245f

Please sign in to comment.