@openclaw/slack 2026.10.10-beta.5 → 2026.10.33

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.
Files changed (99) hide show
  1. package/dist/.setup/action-runtime.runtime-vLxx_7s2.mjs +2 -0
  2. package/dist/.setup/{channel-6YzXl_63.mjs → channel-DQKq-0IZ.mjs} +5 -5
  3. package/dist/.setup/{channel.setup-u6QQdbTa.mjs → channel.setup-CzFw73mU.mjs} +1 -1
  4. package/dist/.setup/{monitor-BFilOuM_.mjs → monitor-Dcd6ymHV.mjs} +3 -3
  5. package/dist/.setup/{pipeline.runtime-BG5swHnj.mjs → pipeline.runtime-CdF95Pej.mjs} +3 -2
  6. package/dist/.setup/{relay-source-oY9SbDiX.mjs → relay-source-BPXstGYg.mjs} +7 -2
  7. package/dist/.setup/{replies-CJwjTqDr.mjs → replies-C60dQn3J.mjs} +1 -1
  8. package/dist/.setup/runtime-setter-api-CMFvhrAr.mjs +3 -0
  9. package/dist/.setup/secret-contract-api-DK9gZldc.mjs +3 -0
  10. package/dist/.setup/{secret-contract-B-Qm6aQQ.mjs → secret-contract-vVRMoE1D.mjs} +2 -0
  11. package/dist/.setup/setup-plugin-api-BGD1TYnK.mjs +3 -0
  12. package/dist/.setup/{setup-surface-9WVQgYCT.mjs → setup-surface--n8VsDvV.mjs} +2 -2
  13. package/dist/.setup/{shared-DpHCoKy2.mjs → shared-BhJHIZs1.mjs} +2 -2
  14. package/dist/.setup/{slash-dispatch.runtime-v5kQqJPh.mjs → slash-dispatch.runtime-DNddQpYP.mjs} +1 -1
  15. package/dist/api.js +2 -2
  16. package/dist/channel-config-api.js +2 -1
  17. package/dist/channel-plugin-api.js +2 -1
  18. package/dist/directory-contract-api.js +2 -1
  19. package/dist/doctor-contract-api.js +2 -1
  20. package/dist/http-routes-api.js +2 -1
  21. package/dist/message-tool-api.js +2 -1
  22. package/dist/runtime-api.js +1 -1
  23. package/dist/runtime-setter-api.js +2 -1
  24. package/dist/secret-contract-api.js +2 -1
  25. package/dist/security-contract-api.js +2 -1
  26. package/dist/setup-entry.js +3 -3
  27. package/dist/setup-plugin-api.js +2 -1
  28. package/node_modules/@slack/bolt/node_modules/body-parser/README.md +17 -13
  29. package/node_modules/@slack/bolt/node_modules/body-parser/lib/read.js +74 -57
  30. package/node_modules/@slack/bolt/node_modules/body-parser/lib/types/json.js +11 -11
  31. package/node_modules/@slack/bolt/node_modules/body-parser/lib/types/urlencoded.js +5 -5
  32. package/node_modules/@slack/bolt/node_modules/body-parser/lib/utils.js +0 -15
  33. package/node_modules/@slack/bolt/node_modules/body-parser/package.json +7 -12
  34. package/node_modules/undici/README.md +25 -3
  35. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  36. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  37. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  38. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  39. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  40. package/node_modules/undici/docs/docs/api/Interceptors.md +13 -6
  41. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  42. package/node_modules/undici/docs/docs/index.md +12 -12
  43. package/node_modules/undici/docs/docs/type-map.json +66 -66
  44. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  45. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  46. package/node_modules/undici/lib/core/connect.js +10 -4
  47. package/node_modules/undici/lib/core/constants.js +12 -1
  48. package/node_modules/undici/lib/core/errors.js +38 -1
  49. package/node_modules/undici/lib/core/request.js +16 -1
  50. package/node_modules/undici/lib/core/symbols.js +2 -0
  51. package/node_modules/undici/lib/core/util.js +26 -1
  52. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  53. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  54. package/node_modules/undici/lib/dispatcher/client-h2.js +46 -14
  55. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  56. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  57. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  58. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  59. package/node_modules/undici/lib/dispatcher/pool-base.js +65 -28
  60. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  61. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  62. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  63. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  64. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  65. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  66. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  67. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  68. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  69. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  70. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  71. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  72. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  73. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  74. package/node_modules/undici/lib/milo/simd.js +1002 -0
  75. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  76. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  77. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  78. package/node_modules/undici/lib/util/cache.js +11 -5
  79. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  80. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  81. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  82. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  83. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  84. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  85. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  86. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  87. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  88. package/node_modules/undici/package.json +7 -5
  89. package/node_modules/undici/types/cache-interceptor.d.ts +10 -0
  90. package/node_modules/undici/types/client.d.ts +10 -4
  91. package/node_modules/undici/types/errors.d.ts +16 -1
  92. package/node_modules/undici/types/h2c-client.d.ts +1 -1
  93. package/node_modules/undici/types/interceptors.d.ts +6 -1
  94. package/package.json +5 -5
  95. package/dist/.setup/action-runtime.runtime-Ck_j1YTn.mjs +0 -1
  96. package/dist/.setup/runtime-setter-api-Cx_PV-xu.mjs +0 -2
  97. package/dist/.setup/secret-contract-api-DB6CMdgc.mjs +0 -2
  98. package/dist/.setup/setup-plugin-api-B18kDKtr.mjs +0 -2
  99. package/dist/.source-module-urls/562d694877afe9d9dcbb3b32a8883c16974738f2aa892c48d45572cdc9a62529.json +0 -1
@@ -17,6 +17,7 @@ const {
17
17
  InformationalError,
18
18
  BodyTimeoutError,
19
19
  HTTPParserError,
20
+ WebAssemblyNotSupportedError,
20
21
  ResponseExceededMaxSizeError
21
22
  } = require('../core/errors.js')
22
23
  const {
@@ -51,10 +52,15 @@ const {
51
52
  kOnError,
52
53
  kResume,
53
54
  kHTTPContext,
54
- kClosed
55
+ kClosed,
56
+ kUseMilo
55
57
  } = require('../core/symbols.js')
56
58
 
57
59
  const constants = require('../llhttp/constants.js')
60
+ // Node.js core bundles only llhttp; experimental Milo remains available in npm builds.
61
+ const { H1Parser, getMiloEnabled } = typeof esbuildDetection === 'undefined'
62
+ ? require('./parser-h1.js')
63
+ : {}
58
64
  const EMPTY_BUF = Buffer.alloc(0)
59
65
  const FastBuffer = Buffer[Symbol.species]
60
66
  const removeAllListeners = util.removeAllListeners
@@ -66,6 +72,11 @@ const kTypeOfService = Symbol('kTypeOfService')
66
72
  let extractBody
67
73
 
68
74
  function lazyllhttp () {
75
+ // Check only when HTTP/1 needs the parser, so other APIs remain usable without WASM.
76
+ if (typeof WebAssembly === 'undefined') {
77
+ throw new WebAssemblyNotSupportedError()
78
+ }
79
+
69
80
  const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined
70
81
 
71
82
  let mod
@@ -88,8 +99,7 @@ function lazyllhttp () {
88
99
  if (useWasmSIMD) {
89
100
  try {
90
101
  mod = new WebAssembly.Module(require('../llhttp/llhttp_simd-wasm.js'))
91
- } catch {
92
- }
102
+ } catch {}
93
103
  }
94
104
 
95
105
  if (!mod) {
@@ -126,7 +136,7 @@ function lazyllhttp () {
126
136
  * @param {number} p
127
137
  * @returns {number}
128
138
  */
129
- wasm_on_message_begin: (p) => {
139
+ wasm_on_message_begin: p => {
130
140
  assert(currentParser.ptr === p)
131
141
  return currentParser.onMessageBegin()
132
142
  },
@@ -178,11 +188,10 @@ function lazyllhttp () {
178
188
  * @param {number} p
179
189
  * @returns {number}
180
190
  */
181
- wasm_on_message_complete: (p) => {
191
+ wasm_on_message_complete: p => {
182
192
  assert(currentParser.ptr === p)
183
193
  return currentParser.onMessageComplete()
184
194
  }
185
-
186
195
  }
187
196
  })
188
197
  }
@@ -215,10 +224,10 @@ const TIMEOUT_KEEP_ALIVE = 8 | USE_NATIVE_TIMER
215
224
 
216
225
  class Parser {
217
226
  /**
218
- * @param {import('./client.js')} client
219
- * @param {import('net').Socket} socket
220
- * @param {*} llhttp
221
- */
227
+ * @param {import('./client.js')} client
228
+ * @param {import('net').Socket} socket
229
+ * @param {*} llhttp
230
+ */
222
231
  constructor (client, socket, { exports }) {
223
232
  this.llhttp = exports
224
233
  this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE)
@@ -245,7 +254,8 @@ class Parser {
245
254
 
246
255
  this.keepAlive = ''
247
256
  this.contentLength = -1
248
- this.connectionKeepAlive = false
257
+ this.hasTransferEncoding = false
258
+ this.connection = ''
249
259
  this.maxResponseSize = client[kMaxResponseSize]
250
260
  }
251
261
 
@@ -253,10 +263,7 @@ class Parser {
253
263
  // If the existing timer and the new timer are of different timer type
254
264
  // (fast or native) or have different delay, we need to clear the existing
255
265
  // timer and set a new one.
256
- if (
257
- delay !== this.timeoutValue ||
258
- (type & USE_FAST_TIMER) ^ (this.timeoutType & USE_FAST_TIMER)
259
- ) {
266
+ if (delay !== this.timeoutValue || (type & USE_FAST_TIMER) ^ (this.timeoutType & USE_FAST_TIMER)) {
260
267
  // If a timeout is already set, clear it with clearTimeout of the fast
261
268
  // timer implementation, as it can clear fast and native timers.
262
269
  if (this.timeout) {
@@ -441,9 +448,7 @@ class Parser {
441
448
  if (ptr) {
442
449
  const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0)
443
450
  message =
444
- 'Response does not match the HTTP/1.1 protocol (' +
445
- Buffer.from(llhttp.memory.buffer, ptr, len).toString() +
446
- ')'
451
+ 'Response does not match the HTTP/1.1 protocol (' + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ')'
447
452
  }
448
453
 
449
454
  return new HTTPParserError(message, constants.ERROR[ret], data)
@@ -521,6 +526,7 @@ class Parser {
521
526
  */
522
527
  onHeaderValue (buf) {
523
528
  let len = this.headers.length
529
+ const isContinuation = (len & 1) === 0
524
530
 
525
531
  if ((len & 1) === 1) {
526
532
  this.headers.push(buf)
@@ -533,19 +539,19 @@ class Parser {
533
539
  if (key.length === 10) {
534
540
  const headerName = util.bufferToLowerCasedHeaderName(key)
535
541
  if (headerName === 'keep-alive') {
536
- this.keepAlive += buf.toString()
542
+ this.keepAlive += (isContinuation || this.keepAlive.length === 0 ? '' : ',') + buf.toString()
537
543
  } else if (headerName === 'connection') {
538
- this.connectionKeepAlive =
539
- this.headers[len - 1].length === 10 &&
540
- util.bufferToLowerCasedHeaderName(this.headers[len - 1]) === 'keep-alive'
544
+ this.connection += (isContinuation || this.connection.length === 0 ? '' : ',') + buf.toString()
541
545
  }
542
546
  } else if (key.length === 14 && util.bufferToLowerCasedHeaderName(key) === 'content-length') {
543
547
  if (this.contentLength === -1) {
544
548
  this.contentLength = 0
545
549
  }
546
550
  for (let i = 0; i < buf.length; i++) {
547
- this.contentLength = (this.contentLength * 10) + (buf[i] - 0x30)
551
+ this.contentLength = this.contentLength * 10 + (buf[i] - 0x30)
548
552
  }
553
+ } else if (key.length === 17 && util.bufferToLowerCasedHeaderName(key) === 'transfer-encoding') {
554
+ this.hasTransferEncoding = true
549
555
  }
550
556
 
551
557
  this.trackHeader(buf.length)
@@ -652,16 +658,27 @@ class Parser {
652
658
  assert(this.timeoutType === TIMEOUT_HEADERS)
653
659
 
654
660
  this.statusCode = statusCode
655
- this.shouldKeepAlive = (
661
+ this.shouldKeepAlive =
656
662
  shouldKeepAlive ||
657
663
  // Override llhttp value which does not allow keepAlive for HEAD.
658
- (request.method === 'HEAD' && !socket[kReset] && this.connectionKeepAlive)
659
- )
664
+ (request.method === 'HEAD' && !socket[kReset] &&
665
+ /(?:^|,)[\t ]*keep-alive[\t ]*(?:,|$)/i.test(this.connection) &&
666
+ !/(?:^|,)[\t ]*close[\t ]*(?:,|$)/i.test(this.connection))
667
+
668
+ // Responses to HEAD and 204/304 responses never carry content
669
+ if (request.method === 'HEAD' || statusCode === 204 || statusCode === 304) {
670
+ // A non-zero Content-Length or Transfer-Encoding on a 204/304 means the
671
+ // server may also have sent content inappropriately, which would then be
672
+ // parsed as the next response on this connection. Accept it, but do not
673
+ // reuse the connection. HEAD requests are fine tho.
674
+ if (request.method !== 'HEAD' && (this.contentLength > 0 || this.hasTransferEncoding)) {
675
+ this.shouldKeepAlive = false
676
+ }
677
+ this.contentLength = -1
678
+ }
660
679
 
661
680
  if (this.statusCode >= 200) {
662
- const bodyTimeout = request.bodyTimeout != null
663
- ? request.bodyTimeout
664
- : client[kBodyTimeout]
681
+ const bodyTimeout = request.bodyTimeout != null ? request.bodyTimeout : client[kBodyTimeout]
665
682
  this.setTimeout(bodyTimeout, TIMEOUT_BODY)
666
683
  } else if (this.timeout) {
667
684
  if (this.timeout.refresh) {
@@ -689,10 +706,7 @@ class Parser {
689
706
  const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null
690
707
 
691
708
  if (keepAliveTimeout != null) {
692
- const timeout = Math.min(
693
- keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
694
- client[kKeepAliveMaxTimeout]
695
- )
709
+ const timeout = Math.min(keepAliveTimeout - client[kKeepAliveTimeoutThreshold], client[kKeepAliveMaxTimeout])
696
710
  if (timeout <= 0) {
697
711
  socket[kReset] = true
698
712
  } else {
@@ -789,8 +803,9 @@ class Parser {
789
803
  this.statusText = ''
790
804
  this.bytesRead = 0
791
805
  this.contentLength = -1
806
+ this.hasTransferEncoding = false
792
807
  this.keepAlive = ''
793
- this.connectionKeepAlive = false
808
+ this.connection = ''
794
809
 
795
810
  this.headers = []
796
811
  this.headersSize = 0
@@ -799,7 +814,7 @@ class Parser {
799
814
  return 0
800
815
  }
801
816
 
802
- if (request.method !== 'HEAD' && contentLength !== -1 && bytesRead !== contentLength) {
817
+ if (contentLength !== -1 && bytesRead !== contentLength) {
803
818
  util.destroy(socket, new ResponseContentLengthMismatchError())
804
819
  return -1
805
820
  }
@@ -887,7 +902,9 @@ function connectH1 (client, socket) {
887
902
  socket[kIdleSocketValidation] = 0
888
903
  socket[kIdleSocketValidationTimeout] = null
889
904
  socket[kSocketUsed] = false
890
- socket[kParser] = new Parser(client, socket, llhttpInstance)
905
+ socket[kParser] = typeof esbuildDetection === 'undefined' && (client[kUseMilo] ?? getMiloEnabled())
906
+ ? new H1Parser(client, socket)
907
+ : new Parser(client, socket, llhttpInstance)
891
908
 
892
909
  util.addListener(socket, 'error', onHttpSocketError)
893
910
  util.addListener(socket, 'readable', onHttpSocketReadable)
@@ -948,8 +965,11 @@ function connectH1 (client, socket) {
948
965
  return true
949
966
  }
950
967
 
951
- if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
952
- (util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))) {
968
+ if (
969
+ client[kRunning] > 0 &&
970
+ util.bodyLength(request.body) !== 0 &&
971
+ (util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))
972
+ ) {
953
973
  // Request with stream or iterator body can error while other requests
954
974
  // are inflight and indirectly error those as well.
955
975
  // Ensure this doesn't happen by waiting for inflight
@@ -968,8 +988,6 @@ function connectH1 (client, socket) {
968
988
  }
969
989
 
970
990
  function onHttpSocketError (err) {
971
- assert(err.code !== 'ERR_TLS_CERT_ALTNAME_INVALID')
972
-
973
991
  const parser = this[kParser]
974
992
 
975
993
  // On Mac OS, we get an ECONNRESET even if there is a full body to be forwarded
@@ -1137,9 +1155,7 @@ function resumeH1 (client) {
1137
1155
  } else if (client[kRunning] > 0 && socket[kParser].statusCode < 200) {
1138
1156
  if (socket[kParser].timeoutType !== TIMEOUT_HEADERS) {
1139
1157
  const request = client[kQueue][client[kRunningIdx]]
1140
- const headersTimeout = request.headersTimeout != null
1141
- ? request.headersTimeout
1142
- : client[kHeadersTimeout]
1158
+ const headersTimeout = request.headersTimeout != null ? request.headersTimeout : client[kHeadersTimeout]
1143
1159
  socket[kParser].setTimeout(headersTimeout, TIMEOUT_HEADERS)
1144
1160
  }
1145
1161
  }
@@ -1196,14 +1212,13 @@ function writeH1 (client, request) {
1196
1212
  // servers and corrupt connection state. Do not
1197
1213
  // re-use the connection for further requests.
1198
1214
 
1199
- const expectsPayload = (
1215
+ const expectsPayload =
1200
1216
  method === 'PUT' ||
1201
1217
  method === 'POST' ||
1202
1218
  method === 'PATCH' ||
1203
1219
  method === 'QUERY' ||
1204
1220
  method === 'PROPFIND' ||
1205
1221
  method === 'PROPPATCH'
1206
- )
1207
1222
 
1208
1223
  if (util.isFormDataLike(body)) {
1209
1224
  if (!extractBody) {
@@ -1252,7 +1267,12 @@ function writeH1 (client, request) {
1252
1267
 
1253
1268
  // https://github.com/nodejs/undici/issues/2046
1254
1269
  // A user agent may send a Content-Length header with 0 value, this should be allowed.
1255
- if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength !== null && request.contentLength !== contentLength) {
1270
+ if (
1271
+ shouldSendContentLength(method) &&
1272
+ contentLength > 0 &&
1273
+ request.contentLength !== null &&
1274
+ request.contentLength !== contentLength
1275
+ ) {
1256
1276
  if (client[kStrictContentLength]) {
1257
1277
  util.errorRequest(client, request, new RequestContentLengthMismatchError())
1258
1278
  return false
@@ -1268,7 +1288,7 @@ function writeH1 (client, request) {
1268
1288
  * @param {Error} [err]
1269
1289
  * @returns {void}
1270
1290
  */
1271
- const abort = (err) => {
1291
+ const abort = err => {
1272
1292
  if (request.aborted || request.completed) {
1273
1293
  return
1274
1294
  }
@@ -1453,14 +1473,9 @@ function writeStream (abort, body, client, request, socket, contentLength, heade
1453
1473
 
1454
1474
  assert(socket.destroyed || (socket[kWriting] && client[kRunning] <= 1))
1455
1475
 
1456
- socket
1457
- .off('drain', onDrain)
1458
- .off('error', onFinished)
1476
+ socket.off('drain', onDrain).off('error', onFinished)
1459
1477
 
1460
- body
1461
- .removeListener('data', onData)
1462
- .removeListener('end', onFinished)
1463
- .removeListener('close', onClose)
1478
+ body.removeListener('data', onData).removeListener('end', onFinished).removeListener('close', onClose)
1464
1479
 
1465
1480
  if (!err) {
1466
1481
  try {
@@ -1479,19 +1494,13 @@ function writeStream (abort, body, client, request, socket, contentLength, heade
1479
1494
  }
1480
1495
  }
1481
1496
 
1482
- body
1483
- .on('data', onData)
1484
- .on('end', onFinished)
1485
- .on('error', onFinished)
1486
- .on('close', onClose)
1497
+ body.on('data', onData).on('end', onFinished).on('error', onFinished).on('close', onClose)
1487
1498
 
1488
1499
  if (body.resume) {
1489
1500
  body.resume()
1490
1501
  }
1491
1502
 
1492
- socket
1493
- .on('drain', onDrain)
1494
- .on('error', onFinished)
1503
+ socket.on('drain', onDrain).on('error', onFinished)
1495
1504
 
1496
1505
  if (body.errorEmitted ?? body.errored) {
1497
1506
  setImmediate(onFinished, body.errored)
@@ -1612,19 +1621,18 @@ async function writeIterable (abort, body, client, request, socket, contentLengt
1612
1621
  }
1613
1622
  }
1614
1623
 
1615
- const waitForDrain = () => new Promise((resolve, reject) => {
1616
- assert(callback === null)
1624
+ const waitForDrain = () =>
1625
+ new Promise((resolve, reject) => {
1626
+ assert(callback === null)
1617
1627
 
1618
- if (socket[kError]) {
1619
- reject(socket[kError])
1620
- } else {
1621
- callback = resolve
1622
- }
1623
- })
1628
+ if (socket[kError]) {
1629
+ reject(socket[kError])
1630
+ } else {
1631
+ callback = resolve
1632
+ }
1633
+ })
1624
1634
 
1625
- socket
1626
- .on('close', onDrain)
1627
- .on('drain', onDrain)
1635
+ socket.on('close', onDrain).on('drain', onDrain)
1628
1636
 
1629
1637
  const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header })
1630
1638
  try {
@@ -1643,9 +1651,7 @@ async function writeIterable (abort, body, client, request, socket, contentLengt
1643
1651
  } catch (err) {
1644
1652
  writer.destroy(err)
1645
1653
  } finally {
1646
- socket
1647
- .off('close', onDrain)
1648
- .off('drain', onDrain)
1654
+ socket.off('close', onDrain).off('drain', onDrain)
1649
1655
  }
1650
1656
  }
1651
1657
 
@@ -1670,10 +1676,27 @@ class AsyncWriter {
1670
1676
  this.expectsPayload = expectsPayload
1671
1677
  this.header = header
1672
1678
  this.abort = abort
1679
+ this.lengthMismatch = false
1673
1680
 
1674
1681
  socket[kWriting] = true
1675
1682
  }
1676
1683
 
1684
+ /**
1685
+ * The body doesn't match the declared content-length and strictContentLength
1686
+ * is off. Warn once, and mark the socket so it isn't reused: on the wire this
1687
+ * request's body no longer ends where the server expects, so anything sent
1688
+ * after it on the same connection would be misread.
1689
+ * @returns {void}
1690
+ */
1691
+ onLengthMismatch () {
1692
+ this.socket[kReset] = true
1693
+
1694
+ if (!this.lengthMismatch) {
1695
+ this.lengthMismatch = true
1696
+ process.emitWarning(new RequestContentLengthMismatchError())
1697
+ }
1698
+ }
1699
+
1677
1700
  /**
1678
1701
  * @param {string|Uint8Array} chunk
1679
1702
  * @returns
@@ -1689,7 +1712,7 @@ class AsyncWriter {
1689
1712
  return false
1690
1713
  }
1691
1714
 
1692
- const len = chunk instanceof Uint8Array ? chunk.byteLength : Buffer.byteLength(chunk)
1715
+ let len = chunk instanceof Uint8Array ? chunk.byteLength : Buffer.byteLength(chunk)
1693
1716
  if (!len) {
1694
1717
  return true
1695
1718
  }
@@ -1700,7 +1723,17 @@ class AsyncWriter {
1700
1723
  throw new RequestContentLengthMismatchError()
1701
1724
  }
1702
1725
 
1703
- process.emitWarning(new RequestContentLengthMismatchError())
1726
+ this.onLengthMismatch()
1727
+
1728
+ // Never write past the declared content-length. The server treats any
1729
+ // extra bytes as the start of the next request, so a body could inject
1730
+ // a request of its own (request smuggling).
1731
+ const remaining = contentLength - bytesWritten
1732
+ if (remaining === 0) {
1733
+ return true
1734
+ }
1735
+ chunk = (typeof chunk === 'string' ? Buffer.from(chunk) : chunk).subarray(0, remaining)
1736
+ len = remaining
1704
1737
  }
1705
1738
 
1706
1739
  socket.cork()
@@ -1775,9 +1808,12 @@ class AsyncWriter {
1775
1808
  if (contentLength !== null && bytesWritten !== contentLength) {
1776
1809
  if (client[kStrictContentLength]) {
1777
1810
  throw new RequestContentLengthMismatchError()
1778
- } else {
1779
- process.emitWarning(new RequestContentLengthMismatchError())
1780
1811
  }
1812
+
1813
+ // The body is shorter than declared, so the server is still waiting for
1814
+ // the rest. Don't let the next request's bytes on this connection be
1815
+ // read as the missing part of this body.
1816
+ this.onLengthMismatch()
1781
1817
  }
1782
1818
 
1783
1819
  if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
@@ -548,8 +548,14 @@ function applyConnectionWindowSize (connectionWindowSize) {
548
548
  }
549
549
 
550
550
  function onHttp2RemoteSettings (settings) {
551
- // Fallbacks are a safe bet, remote setting will always override
552
- this[kClient][kMaxConcurrentStreams] = settings.maxConcurrentStreams ?? this[kClient][kMaxConcurrentStreams]
551
+ const client = this[kClient]
552
+
553
+ // The configured maxConcurrentStreams (default 100) is the client's own
554
+ // ceiling. The server's SETTINGS_MAX_CONCURRENT_STREAMS can lower it, but
555
+ // must not raise it: a default Node.js server advertises 2^32-1.
556
+ const localMaxConcurrentStreams = client[kHTTP2Options].maxConcurrentStreams
557
+ const remoteMaxConcurrentStreams = settings.maxConcurrentStreams ?? client[kMaxConcurrentStreams] ?? localMaxConcurrentStreams
558
+ client[kMaxConcurrentStreams] = Math.min(remoteMaxConcurrentStreams, localMaxConcurrentStreams)
553
559
  /**
554
560
  * From RFC-8441
555
561
  * A sender MUST NOT send a SETTINGS_ENABLE_CONNECT_PROTOCOL parameter
@@ -594,8 +600,6 @@ function onHttp2SendPing (session) {
594
600
  }
595
601
 
596
602
  function onHttp2SessionError (err) {
597
- assert(err.code !== 'ERR_TLS_CERT_ALTNAME_INVALID')
598
-
599
603
  this[kSocket][kError] = err
600
604
 
601
605
  if (this[kReceivedGoAway]) {
@@ -676,6 +680,10 @@ function onHttp2SessionGoAway (errorCode, lastStreamID) {
676
680
  client[kHTTP2Session] = null
677
681
  }
678
682
 
683
+ if (this[kOpenStreams] === 0) {
684
+ unrefH2Session(this)
685
+ }
686
+
679
687
  clearHttp2IdleTimeout(this)
680
688
  clearNoStreamsTimeout(this)
681
689
 
@@ -757,8 +765,6 @@ function onHttp2SocketClose () {
757
765
  }
758
766
 
759
767
  function onHttp2SocketError (err) {
760
- assert(err.code !== 'ERR_TLS_CERT_ALTNAME_INVALID')
761
-
762
768
  this[kError] = err
763
769
 
764
770
  if (this[kHTTP2Session]?.[kReceivedGoAway]) {
@@ -844,25 +850,27 @@ function buildRequestHeaders (reqHeaders) {
844
850
  for (let n = 0; n < reqHeaders.length; n += 2) {
845
851
  const key = reqHeaders[n + 0]
846
852
  const val = reqHeaders[n + 1]
847
- const current = headers[key]
853
+ // Reading headers[key] directly resolves `__proto__` through the prototype
854
+ // chain instead of reporting the header as absent.
855
+ const current = Object.hasOwn(headers, key) ? headers[key] : undefined
848
856
 
849
857
  if (key === 'cookie') {
850
858
  if (current != null) {
851
- headers[key] = Array.isArray(current) ? (current.push(val), current) : [current, val]
859
+ util.setHeader(headers, key, Array.isArray(current) ? (current.push(val), current) : [current, val])
852
860
  } else {
853
- headers[key] = val
861
+ util.setHeader(headers, key, val)
854
862
  }
855
863
 
856
864
  continue
857
865
  }
858
866
 
859
867
  if (typeof val === 'string') {
860
- headers[key] = current ? `${current}, ${val}` : val
868
+ util.setHeader(headers, key, current ? `${current}, ${val}` : val)
861
869
  continue
862
870
  }
863
871
 
864
872
  for (let i = 0; i < val.length; i++) {
865
- headers[key] = headers[key] ? `${headers[key]}, ${val[i]}` : val[i]
873
+ util.setHeader(headers, key, Object.hasOwn(headers, key) ? `${headers[key]}, ${val[i]}` : val[i])
866
874
  }
867
875
  }
868
876
 
@@ -1368,10 +1376,34 @@ function onData (chunk) {
1368
1376
  state.bytesRead += chunk.length
1369
1377
 
1370
1378
  if (request.onResponseData(chunk) === false) {
1371
- stream.pause()
1379
+ pauseResponseStream(stream, state)
1380
+ }
1381
+ }
1382
+
1383
+ // The body timeout measures how long the peer takes to send data. While the
1384
+ // consumer applies backpressure the peer can't send (it's out of flow-control
1385
+ // window), and Http2Stream's timer, which counts stream activity, would fire.
1386
+ // Stop it while paused and start a fresh one on resume, like HTTP/1.1, which
1387
+ // ignores the body timeout while its parser is paused.
1388
+ function pauseResponseStream (stream, state) {
1389
+ stream.pause()
1390
+ if (state.bodyTimeout) {
1391
+ stream.setTimeout(0)
1372
1392
  }
1373
1393
  }
1374
1394
 
1395
+ // Passed to the handler as its resume callback, bound to the stream.
1396
+ function resumeResponseStream () {
1397
+ const stream = this
1398
+ const state = stream[kRequestStreamState]
1399
+
1400
+ if (state != null && state.bodyTimeout && stream.isPaused()) {
1401
+ stream.setTimeout(state.bodyTimeout)
1402
+ }
1403
+
1404
+ stream.resume()
1405
+ }
1406
+
1375
1407
  function onInterimResponse (headers) {
1376
1408
  const stream = this
1377
1409
  const state = stream[kRequestStreamState]
@@ -1446,8 +1478,8 @@ function onResponse (headers) {
1446
1478
  return
1447
1479
  }
1448
1480
 
1449
- if (request.onResponseStart(statusCode, headers, stream.resume.bind(stream), '') === false) {
1450
- stream.pause()
1481
+ if (request.onResponseStart(statusCode, headers, resumeResponseStream.bind(stream), '') === false) {
1482
+ pauseResponseStream(stream, state)
1451
1483
  }
1452
1484
 
1453
1485
  stream.on('data', onData)
@@ -54,7 +54,8 @@ const {
54
54
  kMaxConcurrentStreams,
55
55
  kHostAuthority,
56
56
  kResume,
57
- kHTTP2Options
57
+ kHTTP2Options,
58
+ kUseMilo
58
59
  } = require('../core/symbols.js')
59
60
  const connectH1 = require('./client-h1.js')
60
61
  const connectH2 = require('./client-h2.js')
@@ -136,6 +137,7 @@ class Client extends DispatcherBase {
136
137
  initialWindowSize,
137
138
  connectionWindowSize,
138
139
  pingInterval,
140
+ useMilo,
139
141
  webSocket,
140
142
  h2Options,
141
143
  eventSource
@@ -335,6 +337,7 @@ class Client extends DispatcherBase {
335
337
  initialWindowSize: h2Options?.initialWindowSize ?? initialWindowSize ?? 262144
336
338
  }
337
339
  }
340
+ this[kUseMilo] = useMilo
338
341
 
339
342
  // kQueue is built up of 3 sections separated by
340
343
  // the kRunningIdx and kPendingIdx indices.
@@ -8,6 +8,7 @@ const {
8
8
  InvalidArgumentError
9
9
  } = require('../core/errors')
10
10
  const { kDestroy, kClose, kClosed, kDestroyed, kDispatch } = require('../core/symbols')
11
+ const { defaultWebSocketMaxFragments, defaultWebSocketMaxPayloadSize } = require('../core/constants')
11
12
 
12
13
  const kOnDestroyed = Symbol('onDestroyed')
13
14
  const kOnClosed = Symbol('onClosed')
@@ -41,8 +42,8 @@ class DispatcherBase extends Dispatcher {
41
42
  */
42
43
  get webSocketOptions () {
43
44
  return {
44
- maxFragments: this[kWebSocketOptions].maxFragments ?? 131072,
45
- maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? 128 * 1024 * 1024 // 128 MB default
45
+ maxFragments: this[kWebSocketOptions].maxFragments ?? defaultWebSocketMaxFragments,
46
+ maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? defaultWebSocketMaxPayloadSize
46
47
  }
47
48
  }
48
49
 
@@ -17,12 +17,16 @@ class LegacyHandlerWrapper {
17
17
  }
18
18
 
19
19
  onRequestUpgrade (controller, statusCode, headers, socket) {
20
- const rawHeaders = controller?.rawHeaders ?? toRawHeaders(headers ?? {})
20
+ const rawHeaders = Array.isArray(controller?.rawHeaders)
21
+ ? controller.rawHeaders
22
+ : toRawHeaders(controller?.rawHeaders ?? headers ?? {})
21
23
  this.#handler.onUpgrade?.(statusCode, rawHeaders, socket)
22
24
  }
23
25
 
24
26
  onResponseStart (controller, statusCode, headers, statusMessage) {
25
- const rawHeaders = controller?.rawHeaders ?? toRawHeaders(headers ?? {})
27
+ const rawHeaders = Array.isArray(controller?.rawHeaders)
28
+ ? controller.rawHeaders
29
+ : toRawHeaders(controller?.rawHeaders ?? headers ?? {})
26
30
 
27
31
  if (this.#handler.onHeaders?.(statusCode, rawHeaders, () => controller.resume(), statusMessage) === false) {
28
32
  controller.pause()
@@ -36,7 +40,9 @@ class LegacyHandlerWrapper {
36
40
  }
37
41
 
38
42
  onResponseEnd (controller, trailers) {
39
- const rawTrailers = controller?.rawTrailers ?? toRawHeaders(trailers ?? {})
43
+ const rawTrailers = Array.isArray(controller?.rawTrailers)
44
+ ? controller.rawTrailers
45
+ : toRawHeaders(controller?.rawTrailers ?? trailers ?? {})
40
46
  this.#handler.onComplete?.(rawTrailers)
41
47
  }
42
48
 
@@ -98,6 +104,17 @@ class Dispatcher1Wrapper extends Dispatcher {
98
104
  return this.#dispatcher.dispatch(opts, Dispatcher1Wrapper.wrapHandler(handler))
99
105
  }
100
106
 
107
+ // Older undici versions read WebSocket and EventSource receive limits from
108
+ // the (legacy) global dispatcher, which is this wrapper, so report the
109
+ // wrapped dispatcher's settings.
110
+ get webSocketOptions () {
111
+ return this.#dispatcher.webSocketOptions
112
+ }
113
+
114
+ get eventSourceOptions () {
115
+ return this.#dispatcher.eventSourceOptions
116
+ }
117
+
101
118
  close (...args) {
102
119
  return this.#dispatcher.close(...args)
103
120
  }