Skip to content

Commit

Permalink
deps: update undici to 6.18.1
Browse files Browse the repository at this point in the history
PR-URL: #53073
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
nodejs-github-bot authored and marco-ippolito committed Jul 19, 2024
1 parent 4987a00 commit 2386697
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 128 deletions.
20 changes: 10 additions & 10 deletions deps/undici/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ This section documents our most commonly used API methods. Additional APIs are d
Arguments:

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

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

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

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

Arguments:

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

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

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

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

Arguments:

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

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

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

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

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

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

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

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

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

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

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

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

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

### `undici.setGlobalDispatcher(dispatcher)`

Expand Down
15 changes: 11 additions & 4 deletions deps/undici/src/lib/web/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,6 @@ Reflect.deleteProperty(Headers, 'setHeadersGuard')
Reflect.deleteProperty(Headers, 'getHeadersList')
Reflect.deleteProperty(Headers, 'setHeadersList')

Object.defineProperty(Headers.prototype, util.inspect.custom, {
enumerable: false
})

iteratorMixin('Headers', Headers, kHeadersSortedMap, 0, 1)

Object.defineProperties(Headers.prototype, {
Expand All @@ -642,6 +638,17 @@ Object.defineProperties(Headers.prototype, {
[Symbol.toStringTag]: {
value: 'Headers',
configurable: true
},
[util.inspect.custom]: {
enumerable: false
},
// Compatibility for global headers
[Symbol('headers list')]: {
configurable: false,
enumerable: false,
get: function () {
return getHeadersList(this)
}
}
})

Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/web/websocket/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ class ByteParser extends Writable {

this.#loop = true
this.#state = parserStates.INFO
this.run(callback)
this.#fragments.length = 0
this.run(callback)
})

this.#loop = false
Expand Down
105 changes: 62 additions & 43 deletions deps/undici/src/lib/web/websocket/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

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

/** @type {Uint8Array} */
/** @type {typeof Uint8Array} */
const FastBuffer = Buffer[Symbol.species]

/**
* @typedef {object} SendQueueNode
* @property {Promise<void> | null} promise
* @property {((...args: any[]) => any)} callback
* @property {Buffer | null} frame
*/

class SendQueue {
#queued = new Set()
#size = 0
/**
* @type {FixedQueue}
*/
#queue = new FixedQueue()

/**
* @type {boolean}
*/
#running = false

/** @type {import('net').Socket} */
/** @type {import('node:net').Socket} */
#socket

constructor (socket) {
Expand All @@ -19,66 +34,70 @@ class SendQueue {

add (item, cb, hint) {
if (hint !== sendHints.blob) {
const data = clone(item, hint)

if (this.#size === 0) {
this.#dispatch(data, cb, hint)
const frame = createFrame(item, hint)
if (!this.#running) {
// fast-path
this.#socket.write(frame, cb)
} else {
this.#queued.add([data, cb, true, hint])
this.#size++

this.#run()
/** @type {SendQueueNode} */
const node = {
promise: null,
callback: cb,
frame
}
this.#queue.push(node)
}

return
}

const promise = item.arrayBuffer()
const queue = [null, cb, false, hint]
promise.then((ab) => {
queue[0] = clone(ab, hint)
queue[2] = true
/** @type {SendQueueNode} */
const node = {
promise: item.arrayBuffer().then((ab) => {
node.promise = null
node.frame = createFrame(ab, hint)
}),
callback: cb,
frame: null
}

this.#run()
})
this.#queue.push(node)

this.#queued.add(queue)
this.#size++
if (!this.#running) {
this.#run()
}
}

#run () {
for (const queued of this.#queued) {
const [data, cb, done, hint] = queued

if (!done) return

this.#queued.delete(queued)
this.#size--

this.#dispatch(data, cb, hint)
async #run () {
this.#running = true
const queue = this.#queue
while (!queue.isEmpty()) {
const node = queue.shift()
// wait pending promise
if (node.promise !== null) {
await node.promise
}
// write
this.#socket.write(node.frame, node.callback)
// cleanup
node.callback = node.frame = null
}
this.#running = false
}
}

#dispatch (data, cb, hint) {
const frame = new WebsocketFrameSend()
const opcode = hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY

frame.frameData = data
const buffer = frame.createFrame(opcode)

this.#socket.write(buffer, cb)
}
function createFrame (data, hint) {
return new WebsocketFrameSend(toBuffer(data, hint)).createFrame(hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY)
}

function clone (data, hint) {
function toBuffer (data, hint) {
switch (hint) {
case sendHints.string:
return Buffer.from(data)
case sendHints.arrayBuffer:
case sendHints.blob:
return new FastBuffer(data)
case sendHints.typedArray:
return Buffer.copyBytesFrom(data)
return new FastBuffer(data.buffer, data.byteOffset, data.byteLength)
}
}

Expand Down
Loading

0 comments on commit 2386697

Please sign in to comment.