Skip to content

Commit

Permalink
utilize dnsLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneJeon committed Sep 14, 2021
1 parent 094cb75 commit 7e7606f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions utils/dns-lookup.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7e7606f

Please sign in to comment.