Skip to content

Commit 4d27b32

Browse files
nodejs-github-bottargos
authored andcommitted
deps: update undici to 6.18.1
PR-URL: #53073 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent b941992 commit 4d27b32

File tree

8 files changed

+175
-128
lines changed

8 files changed

+175
-128
lines changed

deps/undici/src/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ This section documents our most commonly used API methods. Additional APIs are d
123123
Arguments:
124124

125125
* **url** `string | URL | UrlObject`
126-
* **options** [`RequestOptions`](./docs/api/Dispatcher.md#parameter-requestoptions)
126+
* **options** [`RequestOptions`](./docs/docs/api/Dispatcher.md#parameter-requestoptions)
127127
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
128128
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
129129
* **maxRedirections** `Integer` - Default: `0`
@@ -132,14 +132,14 @@ Returns a promise with the result of the `Dispatcher.request` method.
132132

133133
Calls `options.dispatcher.request(options)`.
134134

135-
See [Dispatcher.request](./docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./examples/README.md) for examples.
135+
See [Dispatcher.request](./docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./examples/README.md) for examples.
136136

137137
### `undici.stream([url, options, ]factory): Promise`
138138

139139
Arguments:
140140

141141
* **url** `string | URL | UrlObject`
142-
* **options** [`StreamOptions`](./docs/api/Dispatcher.md#parameter-streamoptions)
142+
* **options** [`StreamOptions`](./docs/docs/api/Dispatcher.md#parameter-streamoptions)
143143
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
144144
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
145145
* **maxRedirections** `Integer` - Default: `0`
@@ -149,14 +149,14 @@ Returns a promise with the result of the `Dispatcher.stream` method.
149149

150150
Calls `options.dispatcher.stream(options, factory)`.
151151

152-
See [Dispatcher.stream](./docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
152+
See [Dispatcher.stream](./docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
153153

154154
### `undici.pipeline([url, options, ]handler): Duplex`
155155

156156
Arguments:
157157

158158
* **url** `string | URL | UrlObject`
159-
* **options** [`PipelineOptions`](./docs/api/Dispatcher.md#parameter-pipelineoptions)
159+
* **options** [`PipelineOptions`](./docs/docs/api/Dispatcher.md#parameter-pipelineoptions)
160160
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
161161
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
162162
* **maxRedirections** `Integer` - Default: `0`
@@ -166,7 +166,7 @@ Returns: `stream.Duplex`
166166

167167
Calls `options.dispatch.pipeline(options, handler)`.
168168

169-
See [Dispatcher.pipeline](./docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
169+
See [Dispatcher.pipeline](./docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
170170

171171
### `undici.connect([url, options]): Promise`
172172

@@ -175,7 +175,7 @@ Starts two-way communications with the requested resource using [HTTP CONNECT](h
175175
Arguments:
176176

177177
* **url** `string | URL | UrlObject`
178-
* **options** [`ConnectOptions`](./docs/api/Dispatcher.md#parameter-connectoptions)
178+
* **options** [`ConnectOptions`](./docs/docs/api/Dispatcher.md#parameter-connectoptions)
179179
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
180180
* **maxRedirections** `Integer` - Default: `0`
181181
* **callback** `(err: Error | null, data: ConnectData | null) => void` (optional)
@@ -184,7 +184,7 @@ Returns a promise with the result of the `Dispatcher.connect` method.
184184

185185
Calls `options.dispatch.connect(options)`.
186186

187-
See [Dispatcher.connect](./docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
187+
See [Dispatcher.connect](./docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
188188

189189
### `undici.fetch(input[, init]): Promise`
190190

@@ -335,7 +335,7 @@ Upgrade to a different protocol. See [MDN - HTTP - Protocol upgrade mechanism](h
335335
Arguments:
336336

337337
* **url** `string | URL | UrlObject`
338-
* **options** [`UpgradeOptions`](./docs/api/Dispatcher.md#parameter-upgradeoptions)
338+
* **options** [`UpgradeOptions`](./docs/docs/api/Dispatcher.md#parameter-upgradeoptions)
339339
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
340340
* **maxRedirections** `Integer` - Default: `0`
341341
* **callback** `(error: Error | null, data: UpgradeData) => void` (optional)
@@ -344,7 +344,7 @@ Returns a promise with the result of the `Dispatcher.upgrade` method.
344344

345345
Calls `options.dispatcher.upgrade(options)`.
346346

347-
See [Dispatcher.upgrade](./docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
347+
See [Dispatcher.upgrade](./docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
348348

349349
### `undici.setGlobalDispatcher(dispatcher)`
350350

deps/undici/src/lib/web/fetch/headers.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,6 @@ Reflect.deleteProperty(Headers, 'setHeadersGuard')
626626
Reflect.deleteProperty(Headers, 'getHeadersList')
627627
Reflect.deleteProperty(Headers, 'setHeadersList')
628628

629-
Object.defineProperty(Headers.prototype, util.inspect.custom, {
630-
enumerable: false
631-
})
632-
633629
iteratorMixin('Headers', Headers, kHeadersSortedMap, 0, 1)
634630

635631
Object.defineProperties(Headers.prototype, {
@@ -642,6 +638,17 @@ Object.defineProperties(Headers.prototype, {
642638
[Symbol.toStringTag]: {
643639
value: 'Headers',
644640
configurable: true
641+
},
642+
[util.inspect.custom]: {
643+
enumerable: false
644+
},
645+
// Compatibility for global headers
646+
[Symbol('headers list')]: {
647+
configurable: false,
648+
enumerable: false,
649+
get: function () {
650+
return getHeadersList(this)
651+
}
645652
}
646653
})
647654

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ class ByteParser extends Writable {
240240

241241
this.#loop = true
242242
this.#state = parserStates.INFO
243-
this.run(callback)
244243
this.#fragments.length = 0
244+
this.run(callback)
245245
})
246246

247247
this.#loop = false

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

+62-43
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@
22

33
const { WebsocketFrameSend } = require('./frame')
44
const { opcodes, sendHints } = require('./constants')
5+
const FixedQueue = require('../../dispatcher/fixed-queue')
56

6-
/** @type {Uint8Array} */
7+
/** @type {typeof Uint8Array} */
78
const FastBuffer = Buffer[Symbol.species]
89

10+
/**
11+
* @typedef {object} SendQueueNode
12+
* @property {Promise<void> | null} promise
13+
* @property {((...args: any[]) => any)} callback
14+
* @property {Buffer | null} frame
15+
*/
16+
917
class SendQueue {
10-
#queued = new Set()
11-
#size = 0
18+
/**
19+
* @type {FixedQueue}
20+
*/
21+
#queue = new FixedQueue()
22+
23+
/**
24+
* @type {boolean}
25+
*/
26+
#running = false
1227

13-
/** @type {import('net').Socket} */
28+
/** @type {import('node:net').Socket} */
1429
#socket
1530

1631
constructor (socket) {
@@ -19,66 +34,70 @@ class SendQueue {
1934

2035
add (item, cb, hint) {
2136
if (hint !== sendHints.blob) {
22-
const data = clone(item, hint)
23-
24-
if (this.#size === 0) {
25-
this.#dispatch(data, cb, hint)
37+
const frame = createFrame(item, hint)
38+
if (!this.#running) {
39+
// fast-path
40+
this.#socket.write(frame, cb)
2641
} else {
27-
this.#queued.add([data, cb, true, hint])
28-
this.#size++
29-
30-
this.#run()
42+
/** @type {SendQueueNode} */
43+
const node = {
44+
promise: null,
45+
callback: cb,
46+
frame
47+
}
48+
this.#queue.push(node)
3149
}
32-
3350
return
3451
}
3552

36-
const promise = item.arrayBuffer()
37-
const queue = [null, cb, false, hint]
38-
promise.then((ab) => {
39-
queue[0] = clone(ab, hint)
40-
queue[2] = true
53+
/** @type {SendQueueNode} */
54+
const node = {
55+
promise: item.arrayBuffer().then((ab) => {
56+
node.promise = null
57+
node.frame = createFrame(ab, hint)
58+
}),
59+
callback: cb,
60+
frame: null
61+
}
4162

42-
this.#run()
43-
})
63+
this.#queue.push(node)
4464

45-
this.#queued.add(queue)
46-
this.#size++
65+
if (!this.#running) {
66+
this.#run()
67+
}
4768
}
4869

49-
#run () {
50-
for (const queued of this.#queued) {
51-
const [data, cb, done, hint] = queued
52-
53-
if (!done) return
54-
55-
this.#queued.delete(queued)
56-
this.#size--
57-
58-
this.#dispatch(data, cb, hint)
70+
async #run () {
71+
this.#running = true
72+
const queue = this.#queue
73+
while (!queue.isEmpty()) {
74+
const node = queue.shift()
75+
// wait pending promise
76+
if (node.promise !== null) {
77+
await node.promise
78+
}
79+
// write
80+
this.#socket.write(node.frame, node.callback)
81+
// cleanup
82+
node.callback = node.frame = null
5983
}
84+
this.#running = false
6085
}
86+
}
6187

62-
#dispatch (data, cb, hint) {
63-
const frame = new WebsocketFrameSend()
64-
const opcode = hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY
65-
66-
frame.frameData = data
67-
const buffer = frame.createFrame(opcode)
68-
69-
this.#socket.write(buffer, cb)
70-
}
88+
function createFrame (data, hint) {
89+
return new WebsocketFrameSend(toBuffer(data, hint)).createFrame(hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY)
7190
}
7291

73-
function clone (data, hint) {
92+
function toBuffer (data, hint) {
7493
switch (hint) {
7594
case sendHints.string:
7695
return Buffer.from(data)
7796
case sendHints.arrayBuffer:
7897
case sendHints.blob:
7998
return new FastBuffer(data)
8099
case sendHints.typedArray:
81-
return Buffer.copyBytesFrom(data)
100+
return new FastBuffer(data.buffer, data.byteOffset, data.byteLength)
82101
}
83102
}
84103

0 commit comments

Comments
 (0)