feat(unstable): WebSocket headers field (#30321)

This changes the second argument in the WebSocket constructor to be able
to take an object, which can contain a headers field with which the
headers for the connection can be set.

---------

Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
Leo Kettmeir 2025-08-28 11:44:59 +02:00 committed by GitHub
parent b88c621f22
commit c217928649
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 148 additions and 23 deletions

View file

@ -6,8 +6,6 @@ import { primordials } from "ext:core/mod.js";
import { op_utf8_to_byte_string } from "ext:core/ops";
const {
ArrayPrototypeFind,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
Number,
NumberIsFinite,
NumberIsNaN,
@ -200,16 +198,7 @@ class EventSource extends EventTarget {
);
if (this.#headers) {
const headerList = headerListFromHeaders(initialHeaders);
const headers = this.#headers ?? ArrayPrototypeSlice(
headerList,
0,
headerList.length,
);
if (headerList.length !== 0) {
ArrayPrototypeSplice(headerList, 0, headerList.length);
}
fillHeaders(initialHeaders, headers);
fillHeaders(initialHeaders, this.#headers);
}
const req = newInnerRequest(