@nxtedition/nxt-undici 3.0.3 → 3.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 +2 -0
- package/lib/interceptor/dns.js +11 -2
- package/lib/interceptor/lookup.js +30 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export const interceptors = {
|
|
|
14
14
|
cache: (await import('./interceptor/cache.js')).default,
|
|
15
15
|
requestId: (await import('./interceptor/request-id.js')).default,
|
|
16
16
|
dns: (await import('./interceptor/dns.js')).default,
|
|
17
|
+
lookup: (await import('./interceptor/lookup.js')).default,
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export { parseHeaders } from './utils.js'
|
|
@@ -62,6 +63,7 @@ export async function request(url, opts) {
|
|
|
62
63
|
interceptors.requestBodyFactory(),
|
|
63
64
|
interceptors.log(),
|
|
64
65
|
interceptors.dns(),
|
|
66
|
+
interceptors.lookup(),
|
|
65
67
|
interceptors.requestId(),
|
|
66
68
|
interceptors.responseRetry(),
|
|
67
69
|
interceptors.responseVerify(),
|
package/lib/interceptor/dns.js
CHANGED
|
@@ -52,7 +52,8 @@ export default (opts) => (dispatch) => (opts, handler) => {
|
|
|
52
52
|
|
|
53
53
|
const url = new URL(opts.origin)
|
|
54
54
|
const hostname = url.hostname
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
const callback = (err, address) => {
|
|
56
57
|
if (err) {
|
|
57
58
|
handler.onConnect(() => {})
|
|
58
59
|
handler.onError(err)
|
|
@@ -60,7 +61,15 @@ export default (opts) => (dispatch) => (opts, handler) => {
|
|
|
60
61
|
url.hostname = address
|
|
61
62
|
dispatch({ ...opts, origin: url.origin }, new Handler(opts, hostname, { handler }))
|
|
62
63
|
}
|
|
63
|
-
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const thenable = dns.lookup(new URL(opts.origin), callback)
|
|
67
|
+
if (typeof thenable?.then === 'function') {
|
|
68
|
+
thenable.then(
|
|
69
|
+
(val) => callback(null, val),
|
|
70
|
+
(err) => callback(err),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
64
73
|
} catch (err) {
|
|
65
74
|
handler.onConnect(() => {})
|
|
66
75
|
handler.onError(err)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default (opts) => (dispatch) => (opts, handler) => {
|
|
2
|
+
const lookup = opts.lookup
|
|
3
|
+
|
|
4
|
+
if (!lookup) {
|
|
5
|
+
dispatch(opts, handler)
|
|
6
|
+
return
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const callback = (err, origin) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
handler.onConnect(() => {})
|
|
13
|
+
handler.onError(err)
|
|
14
|
+
} else {
|
|
15
|
+
dispatch({ ...opts, origin }, handler)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const thenable = lookup(new URL(opts.origin), callback)
|
|
20
|
+
if (typeof thenable?.then === 'function') {
|
|
21
|
+
thenable.then(
|
|
22
|
+
(val) => callback(null, val),
|
|
23
|
+
(err) => callback(err),
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
handler.onConnect(() => {})
|
|
28
|
+
handler.onError(err)
|
|
29
|
+
}
|
|
30
|
+
}
|