Skip to content

Commit

Permalink
refactor: defaultLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 10, 2024
1 parent 7ac47fd commit 866794e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const interceptors = {
export { parseHeaders } from './utils.js'
export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'

function defaultLookup(origin, opts, callback) {
callback(null, Array.isArray(origin) ? origin[Math.floor(Math.random() * origin.length)] : origin)
}

function wrapDispatcher(dispatcher) {
let wrappedDispatcher = dispatcherCache.get(dispatcher)
if (wrappedDispatcher == null) {
Expand Down Expand Up @@ -70,15 +74,7 @@ function wrapDispatcher(dispatcher) {
logger: opts.logger ?? null,
dns: opts.dns ?? true,
connect: opts.connect,
lookup:
opts.lookup ??
((origin, opts, callback) =>
callback(
null,
Array.isArray(origin)
? origin[Math.floor(Math.random() * origin.length)]
: origin,
)),
lookup: opts.lookup ?? defaultLookup,
maxRedirections: 0, // TODO (fix): Ugly hack to disable undici redirections.
},
handler,
Expand Down

0 comments on commit 866794e

Please sign in to comment.