undici
Advanced tools
Comparing version 6.18.0 to 6.18.1
@@ -629,6 +629,2 @@ // https://github.com/Ethan-Arrowood/undici-fetch | ||
Object.defineProperty(Headers.prototype, util.inspect.custom, { | ||
enumerable: false | ||
}) | ||
iteratorMixin('Headers', Headers, kHeadersSortedMap, 0, 1) | ||
@@ -646,2 +642,13 @@ | ||
configurable: true | ||
}, | ||
[util.inspect.custom]: { | ||
enumerable: false | ||
}, | ||
// Compatibility for global headers | ||
[Symbol('headers list')]: { | ||
configurable: false, | ||
enumerable: false, | ||
get: function () { | ||
return getHeadersList(this) | ||
} | ||
} | ||
@@ -648,0 +655,0 @@ }) |
@@ -243,4 +243,4 @@ 'use strict' | ||
this.#state = parserStates.INFO | ||
this.#fragments.length = 0 | ||
this.run(callback) | ||
this.#fragments.length = 0 | ||
}) | ||
@@ -247,0 +247,0 @@ |
@@ -5,11 +5,26 @@ 'use strict' | ||
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 {import('net').Socket} */ | ||
/** | ||
* @type {boolean} | ||
*/ | ||
#running = false | ||
/** @type {import('node:net').Socket} */ | ||
#socket | ||
@@ -23,54 +38,58 @@ | ||
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.#queue.push(node) | ||
if (!this.#running) { | ||
this.#run() | ||
}) | ||
this.#queued.add(queue) | ||
this.#size++ | ||
} | ||
} | ||
#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) { | ||
@@ -83,3 +102,3 @@ case sendHints.string: | ||
case sendHints.typedArray: | ||
return Buffer.copyBytesFrom(data) | ||
return new FastBuffer(data.buffer, data.byteOffset, data.byteLength) | ||
} | ||
@@ -86,0 +105,0 @@ } |
{ | ||
"name": "undici", | ||
"version": "6.18.0", | ||
"version": "6.18.1", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
@@ -126,3 +126,3 @@ # undici | ||
* **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) | ||
@@ -136,3 +136,3 @@ * **method** `String` - Default: `PUT` if `options.body`, otherwise `GET` | ||
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. | ||
@@ -144,3 +144,3 @@ ### `undici.stream([url, options, ]factory): Promise` | ||
* **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) | ||
@@ -155,3 +155,3 @@ * **method** `String` - Default: `PUT` if `options.body`, otherwise `GET` | ||
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. | ||
@@ -163,3 +163,3 @@ ### `undici.pipeline([url, options, ]handler): Duplex` | ||
* **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) | ||
@@ -174,3 +174,3 @@ * **method** `String` - Default: `PUT` if `options.body`, otherwise `GET` | ||
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. | ||
@@ -184,3 +184,3 @@ ### `undici.connect([url, options]): Promise` | ||
* **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) | ||
@@ -194,3 +194,3 @@ * **maxRedirections** `Integer` - Default: `0` | ||
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. | ||
@@ -346,3 +346,3 @@ ### `undici.fetch(input[, init]): Promise` | ||
* **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) | ||
@@ -356,3 +356,3 @@ * **maxRedirections** `Integer` - Default: `0` | ||
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. | ||
@@ -359,0 +359,0 @@ ### `undici.setGlobalDispatcher(dispatcher)` |
1131188
23927