pnpm 11.3.0 → 11.4.0

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.
@@ -24,7 +24,6 @@ function defaultFactory (origin, opts) {
24
24
 
25
25
  class Agent extends DispatcherBase {
26
26
  constructor ({ factory = defaultFactory, maxRedirections = 0, connect, ...options } = {}) {
27
-
28
27
  if (typeof factory !== 'function') {
29
28
  throw new InvalidArgumentError('factory must be a function.')
30
29
  }
@@ -279,29 +279,71 @@ class Parser {
279
279
 
280
280
  const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr
281
281
 
282
- if (ret === constants.ERROR.PAUSED_UPGRADE) {
283
- this.onUpgrade(data.slice(offset))
284
- } else if (ret === constants.ERROR.PAUSED) {
285
- this.paused = true
286
- socket.unshift(data.slice(offset))
287
- } else if (ret !== constants.ERROR.OK) {
288
- const ptr = llhttp.llhttp_get_error_reason(this.ptr)
289
- let message = ''
290
- /* istanbul ignore else: difficult to make a test case for */
291
- if (ptr) {
292
- const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0)
293
- message =
294
- 'Response does not match the HTTP/1.1 protocol (' +
295
- Buffer.from(llhttp.memory.buffer, ptr, len).toString() +
296
- ')'
282
+ if (ret !== constants.ERROR.OK) {
283
+ const body = data.subarray(offset)
284
+
285
+ if (ret === constants.ERROR.PAUSED_UPGRADE) {
286
+ this.onUpgrade(body)
287
+ } else if (ret === constants.ERROR.PAUSED) {
288
+ this.paused = true
289
+ socket.unshift(body)
290
+ } else {
291
+ throw this.createError(ret, body)
297
292
  }
298
- throw new HTTPParserError(message, constants.ERROR[ret], data.slice(offset))
299
293
  }
300
294
  } catch (err) {
301
295
  util.destroy(socket, err)
302
296
  }
303
297
  }
304
298
 
299
+ finish () {
300
+ assert(currentParser === null)
301
+ assert(this.ptr != null)
302
+ assert(!this.paused)
303
+
304
+ const { llhttp } = this
305
+
306
+ let ret
307
+
308
+ try {
309
+ currentParser = this
310
+ ret = llhttp.llhttp_finish(this.ptr)
311
+ } finally {
312
+ currentParser = null
313
+ }
314
+
315
+ if (ret === constants.ERROR.OK) {
316
+ return null
317
+ }
318
+
319
+ if (ret === constants.ERROR.PAUSED || ret === constants.ERROR.PAUSED_UPGRADE) {
320
+ this.paused = true
321
+ return null
322
+ }
323
+
324
+ return this.createError(ret, EMPTY_BUF)
325
+ }
326
+
327
+ createError (ret, data) {
328
+ const { llhttp, contentLength, bytesRead } = this
329
+
330
+ if (contentLength && bytesRead !== parseInt(contentLength, 10)) {
331
+ return new ResponseContentLengthMismatchError()
332
+ }
333
+
334
+ const ptr = llhttp.llhttp_get_error_reason(this.ptr)
335
+ let message = ''
336
+ if (ptr) {
337
+ const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0)
338
+ message =
339
+ 'Response does not match the HTTP/1.1 protocol (' +
340
+ Buffer.from(llhttp.memory.buffer, ptr, len).toString() +
341
+ ')'
342
+ }
343
+
344
+ return new HTTPParserError(message, constants.ERROR[ret], data)
345
+ }
346
+
305
347
  destroy () {
306
348
  assert(this.ptr != null)
307
349
  assert(currentParser == null)
@@ -673,8 +715,11 @@ async function connectH1 (client, socket) {
673
715
  // On Mac OS, we get an ECONNRESET even if there is a full body to be forwarded
674
716
  // to the user.
675
717
  if (err.code === 'ECONNRESET' && parser.statusCode && !parser.shouldKeepAlive) {
676
- // We treat all incoming data so for as a valid response.
677
- parser.onMessageComplete()
718
+ const parserErr = parser.finish()
719
+ if (parserErr) {
720
+ this[kError] = parserErr
721
+ this[kClient][kOnError](parserErr)
722
+ }
678
723
  return
679
724
  }
680
725
 
@@ -693,8 +738,10 @@ async function connectH1 (client, socket) {
693
738
  const parser = this[kParser]
694
739
 
695
740
  if (parser.statusCode && !parser.shouldKeepAlive) {
696
- // We treat all incoming data so far as a valid response.
697
- parser.onMessageComplete()
741
+ const parserErr = parser.finish()
742
+ if (parserErr) {
743
+ util.destroy(this, parserErr)
744
+ }
698
745
  return
699
746
  }
700
747
 
@@ -706,8 +753,7 @@ async function connectH1 (client, socket) {
706
753
 
707
754
  if (parser) {
708
755
  if (!this[kError] && parser.statusCode && !parser.shouldKeepAlive) {
709
- // We treat all incoming data so far as a valid response.
710
- parser.onMessageComplete()
756
+ this[kError] = parser.finish() || this[kError]
711
757
  }
712
758
 
713
759
  this[kParser].destroy()
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "6.25.0",
3
+ "version": "6.26.0",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {