@nxtedition/nxt-undici 6.1.0 → 6.1.2
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/cache.js
CHANGED
|
@@ -3,7 +3,6 @@ import { DecoratorHandler, parseCacheControl } from '../utils.js'
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_STORE = new undici.cacheStores.SqliteCacheStore({ location: ':memory:' })
|
|
5
5
|
const DEFAULT_MAX_ENTRY_SIZE = 128 * 1024
|
|
6
|
-
const EMPTY_BUFFER = Buffer.alloc(0)
|
|
7
6
|
const NOOP = () => {}
|
|
8
7
|
|
|
9
8
|
class CacheHandler extends DecoratorHandler {
|
|
@@ -201,9 +200,11 @@ export default () => (dispatch) => (opts, handler) => {
|
|
|
201
200
|
return
|
|
202
201
|
}
|
|
203
202
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
if (body?.byteLength) {
|
|
204
|
+
handler.onData(body)
|
|
205
|
+
if (aborted) {
|
|
206
|
+
return
|
|
207
|
+
}
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
handler.onComplete({})
|
package/lib/interceptor/dns.js
CHANGED
|
@@ -36,12 +36,14 @@ export default () => (dispatch) => {
|
|
|
36
36
|
const cache = new Map()
|
|
37
37
|
const promises = new Map()
|
|
38
38
|
|
|
39
|
-
function resolve(resolve4,
|
|
39
|
+
function resolve(hostname, { resolve4, logger }) {
|
|
40
40
|
let promise = promises.get(hostname)
|
|
41
41
|
if (!promise) {
|
|
42
|
+
logger?.debug({ dns: { hostname } }, 'lookup started')
|
|
42
43
|
promise = new Promise((resolve) =>
|
|
43
44
|
resolve4(hostname, { ttl: true }, (err, records) => {
|
|
44
45
|
if (err) {
|
|
46
|
+
logger?.error({ err, dns: { hostname } }, 'lookup failed')
|
|
45
47
|
resolve([err, null])
|
|
46
48
|
} else {
|
|
47
49
|
const now = getFastNow()
|
|
@@ -53,6 +55,8 @@ export default () => (dispatch) => {
|
|
|
53
55
|
counter: 0,
|
|
54
56
|
}))
|
|
55
57
|
|
|
58
|
+
logger?.debug({ err, dns: { records } }, 'lookup completed')
|
|
59
|
+
|
|
56
60
|
cache.set(hostname, val)
|
|
57
61
|
|
|
58
62
|
resolve([null, val])
|
|
@@ -85,9 +89,10 @@ export default () => (dispatch) => {
|
|
|
85
89
|
let records = cache.get(hostname)
|
|
86
90
|
|
|
87
91
|
const resolve4 = opts.dns.resolve4 || dns.resolve4
|
|
92
|
+
const logger = opts.dns.logger ?? opts.logger
|
|
88
93
|
|
|
89
94
|
if (records == null || records.every((x) => x.expires < now)) {
|
|
90
|
-
const [err, val] = await resolve(resolve4,
|
|
95
|
+
const [err, val] = await resolve(hostname, { resolve4, logger })
|
|
91
96
|
|
|
92
97
|
if (err) {
|
|
93
98
|
throw err
|
|
@@ -97,7 +102,7 @@ export default () => (dispatch) => {
|
|
|
97
102
|
|
|
98
103
|
records = val
|
|
99
104
|
} else if (records.some((x) => x.expires < now + 1e3)) {
|
|
100
|
-
resolve(resolve4,
|
|
105
|
+
resolve(hostname, { resolve4, logger })
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
records.sort(
|