@nxtedition/nxt-undici 4.2.4 → 4.2.6
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 +6 -10
- package/lib/interceptor/request-id.js +1 -12
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -20,6 +20,10 @@ export const interceptors = {
|
|
|
20
20
|
export { parseHeaders } from './utils.js'
|
|
21
21
|
export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'
|
|
22
22
|
|
|
23
|
+
function defaultLookup(origin, opts, callback) {
|
|
24
|
+
callback(null, Array.isArray(origin) ? origin[Math.floor(Math.random() * origin.length)] : origin)
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
function wrapDispatcher(dispatcher) {
|
|
24
28
|
let wrappedDispatcher = dispatcherCache.get(dispatcher)
|
|
25
29
|
if (wrappedDispatcher == null) {
|
|
@@ -60,7 +64,7 @@ function wrapDispatcher(dispatcher) {
|
|
|
60
64
|
headersTimeout: opts.headersTimeout,
|
|
61
65
|
bodyTimeout: opts.bodyTimeout,
|
|
62
66
|
idempotent: opts.idempotent,
|
|
63
|
-
retry: opts.retry ??
|
|
67
|
+
retry: opts.retry ?? 4,
|
|
64
68
|
proxy: opts.proxy ?? false,
|
|
65
69
|
cache: opts.cache ?? false,
|
|
66
70
|
upgrade: opts.upgrade ?? false,
|
|
@@ -70,15 +74,7 @@ function wrapDispatcher(dispatcher) {
|
|
|
70
74
|
logger: opts.logger ?? null,
|
|
71
75
|
dns: opts.dns ?? true,
|
|
72
76
|
connect: opts.connect,
|
|
73
|
-
lookup:
|
|
74
|
-
opts.lookup ??
|
|
75
|
-
((origin, opts, callback) =>
|
|
76
|
-
callback(
|
|
77
|
-
null,
|
|
78
|
-
Array.isArray(origin)
|
|
79
|
-
? origin[Math.floor(Math.random() * origin.length)]
|
|
80
|
-
: origin,
|
|
81
|
-
)),
|
|
77
|
+
lookup: opts.lookup ?? defaultLookup,
|
|
82
78
|
maxRedirections: 0, // TODO (fix): Ugly hack to disable undici redirections.
|
|
83
79
|
},
|
|
84
80
|
handler,
|
|
@@ -12,18 +12,7 @@ function genReqId() {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export default (opts) => (dispatch) => (opts, handler) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (opts.headers?.['request-id']) {
|
|
18
|
-
id = opts.headers['request-id']
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (opts.id) {
|
|
22
|
-
id = id && id !== opts.id ? id + ',' + opts.id : opts.id
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
id = id ? id + ',' + opts.id : genReqId()
|
|
26
|
-
|
|
15
|
+
const id = opts.id ? `${opts.id},${genReqId}` : genReqId()
|
|
27
16
|
return dispatch(
|
|
28
17
|
{
|
|
29
18
|
...opts,
|