@nxtedition/nxt-undici 2.0.36 → 2.0.38
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/readable.js +40 -21
- 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,
|
package/lib/readable.js
CHANGED
|
@@ -125,7 +125,7 @@ export class BodyReadable extends Readable {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
push(chunk) {
|
|
128
|
-
if (this[kConsume] && chunk !== null
|
|
128
|
+
if (this[kConsume] && chunk !== null) {
|
|
129
129
|
consumePush(this[kConsume], chunk)
|
|
130
130
|
return this[kReading] ? super.push(chunk) : true
|
|
131
131
|
}
|
|
@@ -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())
|
|
@@ -232,26 +241,28 @@ async function consume(stream, type) {
|
|
|
232
241
|
reject(rState.errored ?? new TypeError('unusable'))
|
|
233
242
|
}
|
|
234
243
|
} else {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
queueMicrotask(() => {
|
|
245
|
+
stream[kConsume] = {
|
|
246
|
+
type,
|
|
247
|
+
stream,
|
|
248
|
+
resolve,
|
|
249
|
+
reject,
|
|
250
|
+
length: 0,
|
|
251
|
+
body: [],
|
|
252
|
+
}
|
|
243
253
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
254
|
+
stream
|
|
255
|
+
.on('error', function (err) {
|
|
256
|
+
consumeFinish(this[kConsume], err)
|
|
257
|
+
})
|
|
258
|
+
.on('close', function () {
|
|
259
|
+
if (this[kConsume].body !== null) {
|
|
260
|
+
consumeFinish(this[kConsume], new RequestAbortedError())
|
|
261
|
+
}
|
|
262
|
+
})
|
|
253
263
|
|
|
254
|
-
|
|
264
|
+
consumeStart(stream[kConsume])
|
|
265
|
+
})
|
|
255
266
|
}
|
|
256
267
|
})
|
|
257
268
|
}
|
|
@@ -263,8 +274,16 @@ function consumeStart(consume) {
|
|
|
263
274
|
|
|
264
275
|
const { _readableState: state } = consume.stream
|
|
265
276
|
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
if (state.bufferIndex) {
|
|
278
|
+
const start = state.bufferIndex
|
|
279
|
+
const end = state.buffer.length
|
|
280
|
+
for (let n = start; n < end; n++) {
|
|
281
|
+
consumePush(consume, state.buffer[n])
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
for (const chunk of state.buffer) {
|
|
285
|
+
consumePush(consume, chunk)
|
|
286
|
+
}
|
|
268
287
|
}
|
|
269
288
|
|
|
270
289
|
if (state.endEmitted) {
|