From 7e7606f8e9ac4015753be401d0270421479ae8a9 Mon Sep 17 00:00:00 2001 From: Jane Jeon Date: Mon, 13 Sep 2021 21:32:23 -0400 Subject: [PATCH] utilize dnsLookup --- index.js | 2 +- utils/dns-lookup.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 8073ac0..53044c3 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ export default ( timeoutMs = 15000 // global timeout for the ENTIRE function, because I'm afraid of blocking the event loop w/ some of the more compute-intensive shit ) => { const httpClient = httpClientGen(gotOptions) - const dnsLookup = dnsLookupGen(gotOptions.dnsCache) + const dnsLookup = dnsLookupGen(gotOptions) const normalize = normalizeUrl(normalizeUrlOptions, dnsLookup, httpClient) // Normalize URL so that we can search by URL. diff --git a/utils/dns-lookup.js b/utils/dns-lookup.js index 790b247..938964a 100644 --- a/utils/dns-lookup.js +++ b/utils/dns-lookup.js @@ -1,14 +1,18 @@ import { URL } from 'url' import { lookup as nativeLookup } from 'dns/promises' +import { promisify } from 'util' import logger from './logger.js' const debug = logger('utils/dns-lookup.js') -export default dnsCache => { +export default gotOptions => { let lookup - if (dnsCache) { + if (gotOptions.dnsCache) { debug('Using dnsCache.lookupAsync for DNS lookups') - lookup = dnsCache.lookupAsync + lookup = gotOptions.dnsCache.lookupAsync + } else if (gotOptions.dnsLookup) { + debug('Promisifying user-provided dnsLookup') + lookup = promisify(gotOptions.dnsLookup) } else { debug('dnsCache does not exist, falling back to dns/promises') lookup = nativeLookup