@nxtedition/nxt-undici 2.0.35 → 2.0.37

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.
@@ -79,12 +79,24 @@ class Handler {
79
79
 
80
80
  if (this.aborted) {
81
81
  this.logger.debug(
82
- { bytesRead: this.pos, elapsedTime: this.stats.end, stats: this.stats, err },
82
+ {
83
+ ureq: this.opts,
84
+ bytesRead: this.pos,
85
+ elapsedTime: this.stats.end,
86
+ stats: this.stats,
87
+ err,
88
+ },
83
89
  'upstream request aborted',
84
90
  )
85
91
  } else {
86
92
  this.logger.error(
87
- { ureq: this.opts, bytesRead: this.pos, elapsedTime: this.stats.end, err },
93
+ {
94
+ ureq: this.opts,
95
+ bytesRead: this.pos,
96
+ elapsedTime: this.stats.end,
97
+ stats: this.stats,
98
+ err,
99
+ },
88
100
  'upstream request failed',
89
101
  )
90
102
  }
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
  }
@@ -232,26 +232,28 @@ async function consume(stream, type) {
232
232
  reject(rState.errored ?? new TypeError('unusable'))
233
233
  }
234
234
  } else {
235
- stream[kConsume] = {
236
- type,
237
- stream,
238
- resolve,
239
- reject,
240
- length: 0,
241
- body: [],
242
- }
235
+ queueMicrotask(() => {
236
+ stream[kConsume] = {
237
+ type,
238
+ stream,
239
+ resolve,
240
+ reject,
241
+ length: 0,
242
+ body: [],
243
+ }
243
244
 
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
- })
245
+ stream
246
+ .on('error', function (err) {
247
+ consumeFinish(this[kConsume], err)
248
+ })
249
+ .on('close', function () {
250
+ if (this[kConsume].body !== null) {
251
+ consumeFinish(this[kConsume], new RequestAbortedError())
252
+ }
253
+ })
253
254
 
254
- queueMicrotask(() => consumeStart(stream[kConsume]))
255
+ consumeStart(stream[kConsume])
256
+ })
255
257
  }
256
258
  })
257
259
  }
@@ -263,8 +265,16 @@ function consumeStart(consume) {
263
265
 
264
266
  const { _readableState: state } = consume.stream
265
267
 
266
- for (const chunk of state.buffer) {
267
- consumePush(consume, chunk)
268
+ if (state.bufferIndex) {
269
+ const start = state.bufferIndex
270
+ const end = state.buffer.length
271
+ for (let n = start; n < end; n++) {
272
+ consumePush(consume, state.buffer[n])
273
+ }
274
+ } else {
275
+ for (const chunk of state.buffer) {
276
+ consumePush(consume, chunk)
277
+ }
268
278
  }
269
279
 
270
280
  if (state.endEmitted) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.35",
3
+ "version": "2.0.37",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",