@nxtedition/nxt-undici 5.0.3 → 5.1.0
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 +3 -0
- package/lib/interceptor/dns.js +22 -0
- package/lib/utils.js +0 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export const interceptors = {
|
|
|
14
14
|
proxy: (await import('./interceptor/proxy.js')).default,
|
|
15
15
|
cache: (await import('./interceptor/cache.js')).default,
|
|
16
16
|
requestId: (await import('./interceptor/request-id.js')).default,
|
|
17
|
+
dns: (await import('./interceptor/dns.js')).default,
|
|
17
18
|
lookup: (await import('./interceptor/lookup.js')).default,
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -57,6 +58,7 @@ function wrapDispatch(dispatcher) {
|
|
|
57
58
|
interceptors.responseError(),
|
|
58
59
|
interceptors.requestBodyFactory(),
|
|
59
60
|
interceptors.log(),
|
|
61
|
+
interceptors.dns(),
|
|
60
62
|
interceptors.lookup(),
|
|
61
63
|
interceptors.requestId(),
|
|
62
64
|
interceptors.responseRetry(),
|
|
@@ -97,6 +99,7 @@ function wrapDispatch(dispatcher) {
|
|
|
97
99
|
error: opts.error ?? true,
|
|
98
100
|
verify: opts.verify ?? true,
|
|
99
101
|
logger: opts.logger ?? null,
|
|
102
|
+
dns: opts.dns ?? true,
|
|
100
103
|
connect: opts.connect,
|
|
101
104
|
lookup: opts.lookup ?? defaultLookup,
|
|
102
105
|
maxRedirections: 0, // TODO (fix): Ugly hack to disable undici redirections.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
import { resolve4 } from 'node:dns/promises'
|
|
3
|
+
|
|
4
|
+
export default () => (dispatch) => {
|
|
5
|
+
return async (opts, handler) => {
|
|
6
|
+
if (!opts.dns) {
|
|
7
|
+
return dispatch(opts, handler)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const origin = new URL(opts.origin)
|
|
11
|
+
|
|
12
|
+
if (net.isIP(origin.hostname)) {
|
|
13
|
+
return dispatch(opts, handler)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const host = origin.host
|
|
17
|
+
const records = await resolve4(origin.hostname)
|
|
18
|
+
origin.hostname = records[Math.floor(Math.random() * records.length)]
|
|
19
|
+
|
|
20
|
+
return dispatch({ ...opts, origin, headers: { ...opts.headers, host } }, handler)
|
|
21
|
+
}
|
|
22
|
+
}
|
package/lib/utils.js
CHANGED
|
@@ -263,10 +263,6 @@ export class DecoratorHandler {
|
|
|
263
263
|
return this.#handler.onUpgrade?.(...args)
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
onResponseStarted(...args) {
|
|
267
|
-
return this.#handler.onResponseStarted?.(...args)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
266
|
onHeaders(...args) {
|
|
271
267
|
return this.#handler.onHeaders?.(...args)
|
|
272
268
|
}
|
|
@@ -278,10 +274,6 @@ export class DecoratorHandler {
|
|
|
278
274
|
onComplete(...args) {
|
|
279
275
|
return this.#handler.onComplete?.(...args)
|
|
280
276
|
}
|
|
281
|
-
|
|
282
|
-
onBodySent(...args) {
|
|
283
|
-
return this.#handler.onBodySent?.(...args)
|
|
284
|
-
}
|
|
285
277
|
}
|
|
286
278
|
|
|
287
279
|
/**
|