@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 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 && this.readableLength === 0) {
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
- stream[kConsume] = {
236
- type,
237
- stream,
238
- resolve,
239
- reject,
240
- length: 0,
241
- body: [],
242
- }
244
+ queueMicrotask(() => {
245
+ stream[kConsume] = {
246
+ type,
247
+ stream,
248
+ resolve,
249
+ reject,
250
+ length: 0,
251
+ body: [],
252
+ }
243
253
 
244
- stream
245
- .on('error', function (err) {
246
- consumeFinish(this[kConsume], err)
247
- })
248
- .on('close', function () {
249
- if (this[kConsume].body !== null) {
250
- consumeFinish(this[kConsume], new RequestAbortedError())
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
- queueMicrotask(() => consumeStart(stream[kConsume]))
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
- for (const chunk of state.buffer) {
267
- consumePush(consume, chunk)
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.36",
3
+ "version": "2.0.38",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",