(expectedHostname, resolvedAddresses = [])
| 52 | } |
| 53 | |
| 54 | function createPinnedLookup(expectedHostname, resolvedAddresses = []) { |
| 55 | const normalizedExpectedHostname = normalizeHostname(expectedHostname); |
| 56 | const candidates = resolvedAddresses |
| 57 | .map((address) => ({ |
| 58 | address, |
| 59 | family: net.isIP(address), |
| 60 | })) |
| 61 | .filter((entry) => entry.family); |
| 62 | |
| 63 | return (hostname, options, callback) => { |
| 64 | const lookupOptions = typeof options === "function" ? {} : options || {}; |
| 65 | const cb = typeof options === "function" ? options : callback; |
| 66 | const normalizedHostname = normalizeHostname(hostname); |
| 67 | |
| 68 | if (!cb) return; |
| 69 | |
| 70 | if (normalizedHostname !== normalizedExpectedHostname) { |
| 71 | process.nextTick(() => cb(createLookupError(hostname))); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | const requestedFamily = Number(lookupOptions.family) || 0; |
| 76 | const matches = requestedFamily |
| 77 | ? candidates.filter((entry) => entry.family === requestedFamily) |
| 78 | : candidates; |
| 79 | |
| 80 | if (matches.length === 0) { |
| 81 | process.nextTick(() => cb(createLookupError(hostname))); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | process.nextTick(() => { |
| 86 | if (lookupOptions.all) { |
| 87 | cb(null, matches.map((entry) => ({ ...entry }))); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | cb(null, matches[0].address, matches[0].family); |
| 92 | }); |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | async function safeRequest(requestOptions, policyContext = {}) { |
| 97 | const baseOptions = { ...requestOptions }; |
no test coverage detected