@nxtedition/nxt-undici 2.0.37 → 2.0.39
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 -1
- package/lib/interceptor/redirect.js +5 -1
- package/lib/readable.js +9 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -33,7 +33,7 @@ const dispatchers = {
|
|
|
33
33
|
requestId: (await import('./interceptor/request-id.js')).default,
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const dnsCache = new CacheableLookup()
|
|
36
|
+
const dnsCache = new CacheableLookup({ maxTtl: 10e3 })
|
|
37
37
|
const defaultDispatcher = new undici.Agent({
|
|
38
38
|
connect: {
|
|
39
39
|
lookup: dnsCache.lookup,
|
|
@@ -17,6 +17,7 @@ class Handler {
|
|
|
17
17
|
|
|
18
18
|
this.count = 0
|
|
19
19
|
this.location = null
|
|
20
|
+
this.history = []
|
|
20
21
|
|
|
21
22
|
this.handler.onConnect((reason) => {
|
|
22
23
|
this.aborted = true
|
|
@@ -57,6 +58,7 @@ class Handler {
|
|
|
57
58
|
throw new Error(`Missing redirection location .`)
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
this.history.push(this.location)
|
|
60
62
|
this.count += 1
|
|
61
63
|
|
|
62
64
|
if (typeof this.opts.follow === 'function') {
|
|
@@ -67,7 +69,9 @@ class Handler {
|
|
|
67
69
|
}
|
|
68
70
|
} else {
|
|
69
71
|
if (this.count >= this.maxCount) {
|
|
70
|
-
throw new Error(`Max redirections reached: ${this.maxCount}.`)
|
|
72
|
+
throw Object.assign(new Error(`Max redirections reached: ${this.maxCount}.`), {
|
|
73
|
+
history: this.history,
|
|
74
|
+
})
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
|
package/lib/readable.js
CHANGED
|
@@ -177,6 +177,15 @@ export class BodyReadable extends Readable {
|
|
|
177
177
|
return null
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
const contentLength = this.headers['content-length']
|
|
181
|
+
? Number(this.headers['content-length'])
|
|
182
|
+
: null
|
|
183
|
+
|
|
184
|
+
if (contentLength != null && contentLength >= limit) {
|
|
185
|
+
this.on('error', () => {}).destroy()
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
180
189
|
return await new Promise((resolve, reject) => {
|
|
181
190
|
const onAbort = () => {
|
|
182
191
|
this.destroy(signal.reason ?? new AbortError())
|