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 committed Nov 19, 2020
1 parent 49c16ee commit 5fefc20
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/core/index.ts
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 @@ -1758,6 +1758,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 5fefc20

Please sign in to comment.