Skip to content

Commit 5770972

Browse files
deps: update undici to 7.2.1
PR-URL: #56569 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
1 parent f537efd commit 5770972

File tree

13 files changed

+396
-245
lines changed

13 files changed

+396
-245
lines changed

deps/undici/src/docs/docs/api/DiagnosticsChannel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) =>
4040

4141
## `undici:request:headers`
4242

43-
This message is published after the response headers have been received, i.e. the response has been completed.
43+
This message is published after the response headers have been received.
4444

4545
```js
4646
import diagnosticsChannel from 'diagnostics_channel'

deps/undici/src/docs/docs/api/Dispatcher.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ return null
652652

653653
A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.
654654

655-
As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatch.md#example-2---stream-to-fastify-response) for more details.
655+
As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatch.md#example-2-stream-to-fastify-response) for more details.
656656

657657
Arguments:
658658

deps/undici/src/lib/handler/retry-handler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class RetryHandler {
133133
? Math.min(retryAfterHeader, maxTimeout)
134134
: Math.min(minTimeout * timeoutFactor ** (counter - 1), maxTimeout)
135135

136-
setTimeout(() => cb(null), retryTimeout).unref()
136+
setTimeout(() => cb(null), retryTimeout)
137137
}
138138

139139
onResponseStart (controller, statusCode, headers, statusMessage) {
@@ -277,7 +277,7 @@ class RetryHandler {
277277
}
278278

279279
onResponseError (controller, err) {
280-
if (!controller || controller.aborted || isDisturbed(this.opts.body)) {
280+
if (controller?.aborted || isDisturbed(this.opts.body)) {
281281
this.handler.onResponseError?.(controller, err)
282282
return
283283
}

deps/undici/src/lib/interceptor/dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ module.exports = interceptorOpts => {
353353

354354
instance.runLookup(origin, origDispatchOpts, (err, newOrigin) => {
355355
if (err) {
356-
return handler.onError(err)
356+
return handler.onResponseError(null, err)
357357
}
358358

359359
let dispatchOpts = null

deps/undici/src/lib/llhttp/wasm_build_env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
> undici@7.2.0 build:wasm
2+
> undici@7.2.1 build:wasm
33
> node build/wasm.js --docker
44

55
> docker run --rm --platform=linux/x86_64 --user 1001:128 --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/lib/llhttp,target=/home/node/build/lib/llhttp --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/build,target=/home/node/build/build --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/deps,target=/home/node/build/deps -t ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970 node build/wasm.js

deps/undici/src/lib/web/websocket/receiver.js

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const { PerMessageDeflate } = require('./permessage-deflate')
2424

2525
class ByteParser extends Writable {
2626
#buffers = []
27+
#fragmentsBytes = 0
2728
#byteOffset = 0
2829
#loop = false
2930

@@ -208,16 +209,14 @@ class ByteParser extends Writable {
208209
this.#state = parserStates.INFO
209210
} else {
210211
if (!this.#info.compressed) {
211-
this.#fragments.push(body)
212+
this.writeFragments(body)
212213

213214
// If the frame is not fragmented, a message has been received.
214215
// If the frame is fragmented, it will terminate with a fin bit set
215216
// and an opcode of 0 (continuation), therefore we handle that when
216217
// parsing continuation frames, not here.
217218
if (!this.#info.fragmented && this.#info.fin) {
218-
const fullMessage = Buffer.concat(this.#fragments)
219-
websocketMessageReceived(this.#handler, this.#info.binaryType, fullMessage)
220-
this.#fragments.length = 0
219+
websocketMessageReceived(this.#handler, this.#info.binaryType, this.consumeFragments())
221220
}
222221

223222
this.#state = parserStates.INFO
@@ -228,7 +227,7 @@ class ByteParser extends Writable {
228227
return
229228
}
230229

231-
this.#fragments.push(data)
230+
this.writeFragments(data)
232231

233232
if (!this.#info.fin) {
234233
this.#state = parserStates.INFO
@@ -237,11 +236,10 @@ class ByteParser extends Writable {
237236
return
238237
}
239238

240-
websocketMessageReceived(this.#handler, this.#info.binaryType, Buffer.concat(this.#fragments))
239+
websocketMessageReceived(this.#handler, this.#info.binaryType, this.consumeFragments())
241240

242241
this.#loop = true
243242
this.#state = parserStates.INFO
244-
this.#fragments.length = 0
245243
this.run(callback)
246244
})
247245

@@ -265,34 +263,70 @@ class ByteParser extends Writable {
265263
return emptyBuffer
266264
}
267265

268-
if (this.#buffers[0].length === n) {
269-
this.#byteOffset -= this.#buffers[0].length
266+
this.#byteOffset -= n
267+
268+
const first = this.#buffers[0]
269+
270+
if (first.length > n) {
271+
// replace with remaining buffer
272+
this.#buffers[0] = first.subarray(n, first.length)
273+
return first.subarray(0, n)
274+
} else if (first.length === n) {
275+
// prefect match
270276
return this.#buffers.shift()
277+
} else {
278+
let offset = 0
279+
// If Buffer.allocUnsafe is used, extra copies will be made because the offset is non-zero.
280+
const buffer = Buffer.allocUnsafeSlow(n)
281+
while (offset !== n) {
282+
const next = this.#buffers[0]
283+
const length = next.length
284+
285+
if (length + offset === n) {
286+
buffer.set(this.#buffers.shift(), offset)
287+
break
288+
} else if (length + offset > n) {
289+
buffer.set(next.subarray(0, n - offset), offset)
290+
this.#buffers[0] = next.subarray(n - offset)
291+
break
292+
} else {
293+
buffer.set(this.#buffers.shift(), offset)
294+
offset += length
295+
}
296+
}
297+
298+
return buffer
299+
}
300+
}
301+
302+
writeFragments (fragment) {
303+
this.#fragmentsBytes += fragment.length
304+
this.#fragments.push(fragment)
305+
}
306+
307+
consumeFragments () {
308+
const fragments = this.#fragments
309+
310+
if (fragments.length === 1) {
311+
// single fragment
312+
this.#fragmentsBytes = 0
313+
return fragments.shift()
271314
}
272315

273-
const buffer = Buffer.allocUnsafe(n)
274316
let offset = 0
317+
// If Buffer.allocUnsafe is used, extra copies will be made because the offset is non-zero.
318+
const output = Buffer.allocUnsafeSlow(this.#fragmentsBytes)
275319

276-
while (offset !== n) {
277-
const next = this.#buffers[0]
278-
const { length } = next
279-
280-
if (length + offset === n) {
281-
buffer.set(this.#buffers.shift(), offset)
282-
break
283-
} else if (length + offset > n) {
284-
buffer.set(next.subarray(0, n - offset), offset)
285-
this.#buffers[0] = next.subarray(n - offset)
286-
break
287-
} else {
288-
buffer.set(this.#buffers.shift(), offset)
289-
offset += next.length
290-
}
320+
for (let i = 0; i < fragments.length; ++i) {
321+
const buffer = fragments[i]
322+
output.set(buffer, offset)
323+
offset += buffer.length
291324
}
292325

293-
this.#byteOffset -= n
326+
this.#fragments = []
327+
this.#fragmentsBytes = 0
294328

295-
return buffer
329+
return output
296330
}
297331

298332
parseCloseBody (data) {

deps/undici/src/lib/web/websocket/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function toArrayBuffer (buffer) {
8787
if (buffer.byteLength === buffer.buffer.byteLength) {
8888
return buffer.buffer
8989
}
90-
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)
90+
return new Uint8Array(buffer).buffer
9191
}
9292

9393
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy