diff options
Diffstat (limited to 'deps/undici/src/lib/websocket/connection.js')
-rw-r--r-- | deps/undici/src/lib/websocket/connection.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/deps/undici/src/lib/websocket/connection.js b/deps/undici/src/lib/websocket/connection.js index 09770247e3..8c821899f6 100644 --- a/deps/undici/src/lib/websocket/connection.js +++ b/deps/undici/src/lib/websocket/connection.js @@ -13,7 +13,9 @@ const { fireEvent, failWebsocketConnection } = require('./util') const { CloseEvent } = require('./events') const { makeRequest } = require('../fetch/request') const { fetching } = require('../fetch/index') +const { Headers } = require('../fetch/headers') const { getGlobalDispatcher } = require('../global') +const { kHeadersList } = require('../core/symbols') const channels = {} channels.open = diagnosticsChannel.channel('undici:websocket:open') @@ -26,8 +28,9 @@ channels.socketError = diagnosticsChannel.channel('undici:websocket:socket_error * @param {string|string[]} protocols * @param {import('./websocket').WebSocket} ws * @param {(response: any) => void} onEstablish + * @param {Partial<import('../../types/websocket').WebSocketInit>} options */ -function establishWebSocketConnection (url, protocols, ws, onEstablish) { +function establishWebSocketConnection (url, protocols, ws, onEstablish, options) { // 1. Let requestURL be a copy of url, with its scheme set to "http", if url’s // scheme is "ws", and to "https" otherwise. const requestURL = url @@ -48,6 +51,13 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish) { redirect: 'error' }) + // Note: undici extension, allow setting custom headers. + if (options.headers) { + const headersList = new Headers(options.headers)[kHeadersList] + + request.headersList = headersList + } + // 3. Append (`Upgrade`, `websocket`) to request’s header list. // 4. Append (`Connection`, `Upgrade`) to request’s header list. // Note: both of these are handled by undici currently. @@ -88,7 +98,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish) { const controller = fetching({ request, useParallelQueue: true, - dispatcher: getGlobalDispatcher(), + dispatcher: options.dispatcher ?? getGlobalDispatcher(), processResponse (response) { // 1. If response is a network error or its status is not 101, // fail the WebSocket connection. |