@nxtedition/nxt-undici 4.2.17 → 4.2.19
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 +1 -4
- package/lib/interceptor/response-error.js +9 -8
- package/package.json +1 -1
- package/lib/interceptor/dns.js +0 -103
package/lib/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export const interceptors = {
|
|
|
13
13
|
proxy: (await import('./interceptor/proxy.js')).default,
|
|
14
14
|
cache: (await import('./interceptor/cache.js')).default,
|
|
15
15
|
requestId: (await import('./interceptor/request-id.js')).default,
|
|
16
|
-
dns: (await import('./interceptor/dns.js')).default,
|
|
17
16
|
lookup: (await import('./interceptor/lookup.js')).default,
|
|
18
17
|
}
|
|
19
18
|
|
|
@@ -31,7 +30,6 @@ function wrapDispatcher(dispatcher) {
|
|
|
31
30
|
interceptors.responseError(),
|
|
32
31
|
interceptors.requestBodyFactory(),
|
|
33
32
|
interceptors.log(),
|
|
34
|
-
interceptors.dns(),
|
|
35
33
|
interceptors.lookup(),
|
|
36
34
|
interceptors.requestId(),
|
|
37
35
|
interceptors.responseRetry(),
|
|
@@ -59,7 +57,7 @@ function wrapDispatcher(dispatcher) {
|
|
|
59
57
|
query: opts.query,
|
|
60
58
|
headers,
|
|
61
59
|
signal: opts.signal,
|
|
62
|
-
reset: opts.reset ??
|
|
60
|
+
reset: opts.reset ?? false,
|
|
63
61
|
blocking: opts.blocking ?? null,
|
|
64
62
|
headersTimeout: opts.headersTimeout,
|
|
65
63
|
bodyTimeout: opts.bodyTimeout,
|
|
@@ -72,7 +70,6 @@ function wrapDispatcher(dispatcher) {
|
|
|
72
70
|
error: opts.error ?? true,
|
|
73
71
|
verify: opts.verify ?? true,
|
|
74
72
|
logger: opts.logger ?? null,
|
|
75
|
-
dns: opts.dns ?? false,
|
|
76
73
|
connect: opts.connect,
|
|
77
74
|
lookup: opts.lookup ?? defaultLookup,
|
|
78
75
|
maxRedirections: 0, // TODO (fix): Ugly hack to disable undici redirections.
|
|
@@ -91,14 +91,15 @@ class Handler extends DecoratorHandler {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
#decorateError(err) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
return err
|
|
95
|
+
// return Object.assign(err, {
|
|
96
|
+
// url: new URL(this.#opts.path, this.#opts.origin).href,
|
|
97
|
+
// headers: this.#headers,
|
|
98
|
+
// reason: this.#body?.reason,
|
|
99
|
+
// code: this.#body?.code,
|
|
100
|
+
// error: this.#body?.error,
|
|
101
|
+
// body: typeof this.#body !== 'string' || this.#body.length < 1024 ? this.#body : undefined,
|
|
102
|
+
// })
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
|
package/package.json
CHANGED
package/lib/interceptor/dns.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert'
|
|
2
|
-
import net from 'node:net'
|
|
3
|
-
import dns from 'node:dns'
|
|
4
|
-
import { DecoratorHandler } from '../utils.js'
|
|
5
|
-
|
|
6
|
-
const DEFAULT_RESOLVER = {
|
|
7
|
-
lookup(hostname, options, callback) {
|
|
8
|
-
dns.lookup(hostname, options, callback)
|
|
9
|
-
},
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class Handler extends DecoratorHandler {
|
|
13
|
-
#handler
|
|
14
|
-
#resolver
|
|
15
|
-
#key
|
|
16
|
-
|
|
17
|
-
constructor({ resolver, key }, { handler }) {
|
|
18
|
-
super(handler)
|
|
19
|
-
|
|
20
|
-
this.#handler = handler
|
|
21
|
-
this.#resolver = resolver
|
|
22
|
-
this.#key = key
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
onError(err) {
|
|
26
|
-
if (
|
|
27
|
-
err.code &&
|
|
28
|
-
[
|
|
29
|
-
'ECONNRESET',
|
|
30
|
-
'ECONNREFUSED',
|
|
31
|
-
'ENOTFOUND',
|
|
32
|
-
'ENETDOWN',
|
|
33
|
-
'ENETUNREACH',
|
|
34
|
-
'EHOSTDOWN',
|
|
35
|
-
'EHOSTUNREACH',
|
|
36
|
-
'EHOSTNOTFOUND',
|
|
37
|
-
'ENODATA',
|
|
38
|
-
'EPIPE',
|
|
39
|
-
].includes(err.code)
|
|
40
|
-
) {
|
|
41
|
-
this.#resolver.clear(this.#key)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return this.#handler.onError(err)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default (interceptorOpts) => (dispatch) => (opts, handler) => {
|
|
49
|
-
const dns = opts.dns
|
|
50
|
-
|
|
51
|
-
if (!dns) {
|
|
52
|
-
return dispatch(opts, handler)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
resolver = interceptorOpts?.resolver ?? DEFAULT_RESOLVER,
|
|
57
|
-
family = interceptorOpts?.family,
|
|
58
|
-
hints = interceptorOpts?.hints,
|
|
59
|
-
order = interceptorOpts?.order ?? 'ipv4first',
|
|
60
|
-
all = interceptorOpts?.all ?? true,
|
|
61
|
-
} = dns
|
|
62
|
-
|
|
63
|
-
assert(typeof resolver.lookup === 'function')
|
|
64
|
-
|
|
65
|
-
const { hostname, host } = new URL(opts.origin)
|
|
66
|
-
|
|
67
|
-
if (net.isIP(hostname) || opts.headers?.host) {
|
|
68
|
-
return dispatch(opts, handler)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const callback = (err, val) => {
|
|
72
|
-
if (err) {
|
|
73
|
-
handler.onError(err)
|
|
74
|
-
} else {
|
|
75
|
-
const url = new URL(opts.origin)
|
|
76
|
-
url.hostname = Array.isArray(val)
|
|
77
|
-
? val[Math.floor(val.length * Math.random())].address
|
|
78
|
-
: (val?.address ?? val)
|
|
79
|
-
dispatch(
|
|
80
|
-
{
|
|
81
|
-
...opts,
|
|
82
|
-
origin: url.origin,
|
|
83
|
-
headers: { ...opts.headers, host },
|
|
84
|
-
},
|
|
85
|
-
resolver.clear ? new Handler({ resolver, key: hostname }, { handler }) : handler,
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
const thenable = resolver.lookup(hostname, { family, hints, order, all }, callback)
|
|
92
|
-
if (typeof thenable?.then === 'function') {
|
|
93
|
-
thenable.then(
|
|
94
|
-
(val) => callback(null, val),
|
|
95
|
-
(err) => callback(err),
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
} catch (err) {
|
|
99
|
-
handler.onError(err)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return true
|
|
103
|
-
}
|