Skip to content

Commit

Permalink
Fix dnsCache: true having no effect
Browse files Browse the repository at this point in the history
Fixes #1372
  • Loading branch information
szmarczak committed Jul 28, 2020
1 parent e02845f commit 043c950
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -888,7 +890,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {

// `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)}`);
}
Expand Down
12 changes: 12 additions & 0 deletions test/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 043c950

Please sign in to comment.