@@ -28097,10 +28097,6 @@ Reflect.deleteProperty(Headers, 'setHeadersGuard')
2809728097Reflect.deleteProperty(Headers, 'getHeadersList')
2809828098Reflect.deleteProperty(Headers, 'setHeadersList')
2809928099
28100- Object.defineProperty(Headers.prototype, util.inspect.custom, {
28101- enumerable: false
28102- })
28103-
2810428100iteratorMixin('Headers', Headers, kHeadersSortedMap, 0, 1)
2810528101
2810628102Object.defineProperties(Headers.prototype, {
@@ -28113,6 +28109,17 @@ Object.defineProperties(Headers.prototype, {
2811328109 [Symbol.toStringTag]: {
2811428110 value: 'Headers',
2811528111 configurable: true
28112+ },
28113+ [util.inspect.custom]: {
28114+ enumerable: false
28115+ },
28116+ // Compatibility for global headers
28117+ [Symbol('headers list')]: {
28118+ configurable: false,
28119+ enumerable: false,
28120+ get: function () {
28121+ return getHeadersList(this)
28122+ }
2811628123 }
2811728124})
2811828125
@@ -36828,8 +36835,8 @@ class ByteParser extends Writable {
3682836835
3682936836 this.#loop = true
3683036837 this.#state = parserStates.INFO
36831- this.run(callback)
3683236838 this.#fragments.length = 0
36839+ this.run(callback)
3683336840 })
3683436841
3683536842 this.#loop = false
@@ -37022,15 +37029,30 @@ module.exports = {
3702237029
3702337030const { WebsocketFrameSend } = __nccwpck_require__(2391)
3702437031const { opcodes, sendHints } = __nccwpck_require__(3587)
37032+ const FixedQueue = __nccwpck_require__(5158)
3702537033
37026- /** @type {Uint8Array} */
37034+ /** @type {typeof Uint8Array} */
3702737035const FastBuffer = Buffer[Symbol.species]
3702837036
37037+ /**
37038+ * @typedef {object} SendQueueNode
37039+ * @property {Promise<void> | null} promise
37040+ * @property {((...args: any[]) => any)} callback
37041+ * @property {Buffer | null} frame
37042+ */
37043+
3702937044class SendQueue {
37030- #queued = new Set()
37031- #size = 0
37045+ /**
37046+ * @type {FixedQueue}
37047+ */
37048+ #queue = new FixedQueue()
37049+
37050+ /**
37051+ * @type {boolean}
37052+ */
37053+ #running = false
3703237054
37033- /** @type {import('net').Socket} */
37055+ /** @type {import('node: net').Socket} */
3703437056 #socket
3703537057
3703637058 constructor (socket) {
@@ -37039,66 +37061,70 @@ class SendQueue {
3703937061
3704037062 add (item, cb, hint) {
3704137063 if (hint !== sendHints.blob) {
37042- const data = clone (item, hint)
37043-
37044- if (this.#size === 0) {
37045- this.#dispatch(data , cb, hint )
37064+ const frame = createFrame (item, hint)
37065+ if (!this.#running) {
37066+ // fast-path
37067+ this.#socket.write(frame , cb)
3704637068 } else {
37047- this.#queued.add([data, cb, true, hint])
37048- this.#size++
37049-
37050- this.#run()
37069+ /** @type {SendQueueNode} */
37070+ const node = {
37071+ promise: null,
37072+ callback: cb,
37073+ frame
37074+ }
37075+ this.#queue.push(node)
3705137076 }
37052-
3705337077 return
3705437078 }
3705537079
37056- const promise = item.arrayBuffer()
37057- const queue = [null, cb, false, hint]
37058- promise.then((ab) => {
37059- queue[0] = clone(ab, hint)
37060- queue[2] = true
37080+ /** @type {SendQueueNode} */
37081+ const node = {
37082+ promise: item.arrayBuffer().then((ab) => {
37083+ node.promise = null
37084+ node.frame = createFrame(ab, hint)
37085+ }),
37086+ callback: cb,
37087+ frame: null
37088+ }
37089+
37090+ this.#queue.push(node)
3706137091
37092+ if (!this.#running) {
3706237093 this.#run()
37063- })
37064-
37065- this.#queued.add(queue)
37066- this.#size++
37094+ }
3706737095 }
3706837096
37069- #run () {
37070- for (const queued of this.#queued) {
37071- const [data, cb, done, hint] = queued
37072-
37073- if (!done) return
37074-
37075- this.#queued.delete(queued)
37076- this.#size--
37077-
37078- this.#dispatch(data, cb, hint)
37097+ async #run () {
37098+ this.#running = true
37099+ const queue = this.#queue
37100+ while (!queue.isEmpty()) {
37101+ const node = queue.shift()
37102+ // wait pending promise
37103+ if (node.promise !== null) {
37104+ await node.promise
37105+ }
37106+ // write
37107+ this.#socket.write(node.frame, node.callback)
37108+ // cleanup
37109+ node.callback = node.frame = null
3707937110 }
37111+ this.#running = false
3708037112 }
37113+ }
3708137114
37082- #dispatch (data, cb, hint) {
37083- const frame = new WebsocketFrameSend()
37084- const opcode = hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY
37085-
37086- frame.frameData = data
37087- const buffer = frame.createFrame(opcode)
37088-
37089- this.#socket.write(buffer, cb)
37090- }
37115+ function createFrame (data, hint) {
37116+ return new WebsocketFrameSend(toBuffer(data, hint)).createFrame(hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY)
3709137117}
3709237118
37093- function clone (data, hint) {
37119+ function toBuffer (data, hint) {
3709437120 switch (hint) {
3709537121 case sendHints.string:
3709637122 return Buffer.from(data)
3709737123 case sendHints.arrayBuffer:
3709837124 case sendHints.blob:
3709937125 return new FastBuffer(data)
3710037126 case sendHints.typedArray:
37101- return Buffer.copyBytesFrom (data)
37127+ return new FastBuffer (data.buffer, data.byteOffset, data.byteLength )
3710237128 }
3710337129}
3710437130
0 commit comments