@nxtedition/nxt-undici 6.2.2 → 6.2.3
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/interceptor/dns.js +5 -29
- package/package.json +1 -1
package/lib/interceptor/dns.js
CHANGED
|
@@ -28,33 +28,16 @@ class Handler extends DecoratorHandler {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
class DefaultCache {
|
|
32
|
-
#map = new Map()
|
|
33
|
-
|
|
34
|
-
set(hostname, records) {
|
|
35
|
-
this.#map.set(hostname, records)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get(hostname) {
|
|
39
|
-
return this.#map.get(hostname)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
delete(hostname) {
|
|
43
|
-
this.#map.delete(hostname)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const DEFAULT_CACHES = new Map()
|
|
48
|
-
|
|
49
31
|
export default () => (dispatch) => {
|
|
32
|
+
const cache = new Map()
|
|
50
33
|
const promises = new Map()
|
|
51
34
|
|
|
52
|
-
function resolve(hostname, {
|
|
35
|
+
function resolve(hostname, { logger }) {
|
|
53
36
|
let promise = promises.get(hostname)
|
|
54
37
|
if (!promise) {
|
|
55
38
|
logger?.debug({ dns: { hostname } }, 'lookup started')
|
|
56
39
|
promise = new Promise((resolve) =>
|
|
57
|
-
resolve4(hostname, { ttl: true }, (err, records) => {
|
|
40
|
+
dns.resolve4(hostname, { ttl: true }, (err, records) => {
|
|
58
41
|
promises.delete(hostname)
|
|
59
42
|
|
|
60
43
|
if (err) {
|
|
@@ -99,19 +82,12 @@ export default () => (dispatch) => {
|
|
|
99
82
|
|
|
100
83
|
const now = getFastNow()
|
|
101
84
|
|
|
102
|
-
const resolve4 = opts.dns.resolve || opts.dns.resolve4 || dns.resolve4
|
|
103
85
|
const logger = opts.dns.logger ?? opts.logger
|
|
104
86
|
|
|
105
|
-
let cache = opts.dns.cache ?? DEFAULT_CACHES.get(resolve4)
|
|
106
|
-
if (!cache) {
|
|
107
|
-
cache = new DefaultCache()
|
|
108
|
-
DEFAULT_CACHES.set(resolve4, cache)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
87
|
let records = cache.get(hostname)
|
|
112
88
|
|
|
113
89
|
if (records == null || records.every((x) => x.expires < now)) {
|
|
114
|
-
const [err, val] = await resolve(hostname, {
|
|
90
|
+
const [err, val] = await resolve(hostname, { logger })
|
|
115
91
|
|
|
116
92
|
if (err) {
|
|
117
93
|
throw err
|
|
@@ -121,7 +97,7 @@ export default () => (dispatch) => {
|
|
|
121
97
|
|
|
122
98
|
records = val
|
|
123
99
|
} else if (records.some((x) => x.expires < now + 1e3)) {
|
|
124
|
-
resolve(hostname, {
|
|
100
|
+
resolve(hostname, { logger })
|
|
125
101
|
}
|
|
126
102
|
|
|
127
103
|
records.sort(
|