@nxtedition/nxt-undici 6.2.31 → 6.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +24 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -26,7 +26,29 @@ export { parseHeaders } from './utils.js'
|
|
|
26
26
|
export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from '@nxtedition/undici'
|
|
27
27
|
|
|
28
28
|
function defaultLookup(origin, opts, callback) {
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
if (Array.isArray(origin)) {
|
|
31
|
+
origin = origin[Math.floor(Math.random() * origin.length)]
|
|
32
|
+
} else if (origin != null && typeof origin === 'object') {
|
|
33
|
+
const protocol = origin.protocol || 'http:'
|
|
34
|
+
|
|
35
|
+
let host = origin.host
|
|
36
|
+
if (!host && origin.hostname) {
|
|
37
|
+
const port = origin.port || (protocol === 'https:' ? 443 : 80)
|
|
38
|
+
host = `${origin.hostname}:${port}`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!host) {
|
|
42
|
+
throw new Error('invalid url')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
origin = `${protocol}//${host}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
callback(null, origin)
|
|
49
|
+
} catch (err) {
|
|
50
|
+
callback(err, null)
|
|
51
|
+
}
|
|
30
52
|
}
|
|
31
53
|
|
|
32
54
|
export function compose(...interceptors) {
|
|
@@ -61,12 +83,12 @@ function wrapDispatch(dispatcher) {
|
|
|
61
83
|
dispatcher,
|
|
62
84
|
interceptors.log({ bindings: { intercept: 'upstream' } }),
|
|
63
85
|
interceptors.requestBodyFactory(),
|
|
64
|
-
interceptors.lookup(),
|
|
65
86
|
interceptors.responseRetry(),
|
|
66
87
|
interceptors.responseVerify(),
|
|
67
88
|
interceptors.proxy(),
|
|
68
89
|
interceptors.cache(),
|
|
69
90
|
interceptors.redirect(),
|
|
91
|
+
interceptors.lookup(),
|
|
70
92
|
interceptors.log({ bindings: { intercept: 'downstream' } }),
|
|
71
93
|
interceptors.requestId(),
|
|
72
94
|
interceptors.responseError(),
|