undici 6.20.1 → 6.21.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.
@@ -220,6 +220,11 @@ const setupConnectTimeout = process.platform === 'win32'
220
220
  * @param {number} opts.port
221
221
  */
222
222
  function onConnectTimeout (socket, opts) {
223
+ // The socket could be already garbage collected
224
+ if (socket == null) {
225
+ return
226
+ }
227
+
223
228
  let message = 'Connect Timeout Error'
224
229
  if (Array.isArray(socket.autoSelectFamilyAttemptedAddresses)) {
225
230
  message += ` (attempted addresses: ${socket.autoSelectFamilyAttemptedAddresses.join(', ')},`
@@ -229,7 +229,7 @@ class RetryHandler {
229
229
  return false
230
230
  }
231
231
 
232
- const { start, size, end = size } = contentRange
232
+ const { start, size, end = size - 1 } = contentRange
233
233
 
234
234
  assert(this.start === start, 'content-range mismatch')
235
235
  assert(this.end == null || this.end === end, 'content-range mismatch')
@@ -252,7 +252,7 @@ class RetryHandler {
252
252
  )
253
253
  }
254
254
 
255
- const { start, size, end = size } = range
255
+ const { start, size, end = size - 1 } = range
256
256
  assert(
257
257
  start != null && Number.isFinite(start),
258
258
  'content-range mismatch'
@@ -266,7 +266,7 @@ class RetryHandler {
266
266
  // We make our best to checkpoint the body for further range headers
267
267
  if (this.end == null) {
268
268
  const contentLength = headers['content-length']
269
- this.end = contentLength != null ? Number(contentLength) : null
269
+ this.end = contentLength != null ? Number(contentLength) - 1 : null
270
270
  }
271
271
 
272
272
  assert(Number.isFinite(this.start))
@@ -37,6 +37,7 @@ class Cache {
37
37
  webidl.illegalConstructor()
38
38
  }
39
39
 
40
+ webidl.util.markAsUncloneable(this)
40
41
  this.#relevantRequestResponseList = arguments[1]
41
42
  }
42
43
 
@@ -16,6 +16,8 @@ class CacheStorage {
16
16
  if (arguments[0] !== kConstruct) {
17
17
  webidl.illegalConstructor()
18
18
  }
19
+
20
+ webidl.util.markAsUncloneable(this)
19
21
  }
20
22
 
21
23
  async match (request, options = {}) {
@@ -105,6 +105,8 @@ class EventSource extends EventTarget {
105
105
  // 1. Let ev be a new EventSource object.
106
106
  super()
107
107
 
108
+ webidl.util.markAsUncloneable(this)
109
+
108
110
  const prefix = 'EventSource constructor'
109
111
  webidl.argumentLengthCheck(arguments, 1, prefix)
110
112
 
@@ -14,6 +14,8 @@ const File = globalThis.File ?? NativeFile
14
14
  // https://xhr.spec.whatwg.org/#formdata
15
15
  class FormData {
16
16
  constructor (form) {
17
+ webidl.util.markAsUncloneable(this)
18
+
17
19
  if (form !== undefined) {
18
20
  throw webidl.errors.conversionFailed({
19
21
  prefix: 'FormData constructor',
@@ -359,6 +359,8 @@ class Headers {
359
359
  #headersList
360
360
 
361
361
  constructor (init = undefined) {
362
+ webidl.util.markAsUncloneable(this)
363
+
362
364
  if (init === kConstruct) {
363
365
  return
364
366
  }
@@ -2137,7 +2137,7 @@ async function httpNetworkFetch (
2137
2137
 
2138
2138
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
2139
2139
  if (codings.length !== 0 && request.method !== 'HEAD' && request.method !== 'CONNECT' && !nullBodyStatus.includes(status) && !willFollow) {
2140
- for (let i = 0; i < codings.length; ++i) {
2140
+ for (let i = codings.length - 1; i >= 0; --i) {
2141
2141
  const coding = codings[i]
2142
2142
  // https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
2143
2143
  if (coding === 'x-gzip' || coding === 'gzip') {
@@ -82,6 +82,7 @@ let patchMethodWarning = false
82
82
  class Request {
83
83
  // https://fetch.spec.whatwg.org/#dom-request
84
84
  constructor (input, init = {}) {
85
+ webidl.util.markAsUncloneable(this)
85
86
  if (input === kConstruct) {
86
87
  return
87
88
  }
@@ -110,6 +110,7 @@ class Response {
110
110
 
111
111
  // https://fetch.spec.whatwg.org/#dom-response
112
112
  constructor (body = null, init = {}) {
113
+ webidl.util.markAsUncloneable(this)
113
114
  if (body === kConstruct) {
114
115
  return
115
116
  }
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { types, inspect } = require('node:util')
4
+ const { markAsUncloneable } = require('node:worker_threads')
4
5
  const { toUSVString } = require('../../core/util')
5
6
 
6
7
  /** @type {import('../../../types/webidl').Webidl} */
@@ -86,6 +87,7 @@ webidl.util.Type = function (V) {
86
87
  }
87
88
  }
88
89
 
90
+ webidl.util.markAsUncloneable = markAsUncloneable || (() => {})
89
91
  // https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
90
92
  webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
91
93
  let upperBound
@@ -14,6 +14,7 @@ class MessageEvent extends Event {
14
14
  constructor (type, eventInitDict = {}) {
15
15
  if (type === kConstruct) {
16
16
  super(arguments[1], arguments[2])
17
+ webidl.util.markAsUncloneable(this)
17
18
  return
18
19
  }
19
20
 
@@ -26,6 +27,7 @@ class MessageEvent extends Event {
26
27
  super(type, eventInitDict)
27
28
 
28
29
  this.#eventInit = eventInitDict
30
+ webidl.util.markAsUncloneable(this)
29
31
  }
30
32
 
31
33
  get data () {
@@ -112,6 +114,7 @@ class CloseEvent extends Event {
112
114
  super(type, eventInitDict)
113
115
 
114
116
  this.#eventInit = eventInitDict
117
+ webidl.util.markAsUncloneable(this)
115
118
  }
116
119
 
117
120
  get wasClean () {
@@ -142,6 +145,7 @@ class ErrorEvent extends Event {
142
145
  webidl.argumentLengthCheck(arguments, 1, prefix)
143
146
 
144
147
  super(type, eventInitDict)
148
+ webidl.util.markAsUncloneable(this)
145
149
 
146
150
  type = webidl.converters.DOMString(type, prefix, 'type')
147
151
  eventInitDict = webidl.converters.ErrorEventInit(eventInitDict ?? {})
@@ -51,6 +51,8 @@ class WebSocket extends EventTarget {
51
51
  constructor (url, protocols = []) {
52
52
  super()
53
53
 
54
+ webidl.util.markAsUncloneable(this)
55
+
54
56
  const prefix = 'WebSocket constructor'
55
57
  webidl.argumentLengthCheck(arguments, 1, prefix)
56
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "6.20.1",
3
+ "version": "6.21.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": {
package/types/webidl.d.ts CHANGED
@@ -67,6 +67,12 @@ interface WebidlUtil {
67
67
  * Stringifies {@param V}
68
68
  */
69
69
  Stringify (V: any): string
70
+
71
+ /**
72
+ * Mark a value as uncloneable for Node.js.
73
+ * This is only effective in some newer Node.js versions.
74
+ */
75
+ markAsUncloneable (V: any): void
70
76
  }
71
77
 
72
78
  interface WebidlConverters {