| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8c8525c commit 64fc625
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,23 +209,17 @@ function onClientResponseFinish({ request }) { | |||
| 209 | 209 | // TODO: Move Network.webSocketCreated to the actual creation time of the WebSocket. | |
| 210 | 210 | // undici:websocket:open fires when the connection is established, but this results | |
| 211 | 211 | // in an inaccurate stack trace. | |
| 212 | - function onWebSocketOpen({ websocket }) { | ||
| 212 | + function onWebSocketOpen({ websocket, handshakeResponse }) { | ||
| 213 | 213 | websocket[kInspectorRequestId] = getNextRequestId(); | |
| 214 | 214 | const url = websocket.url.toString(); | |
| 215 | 215 | Network.webSocketCreated({ | |
| 216 | 216 | requestId: websocket[kInspectorRequestId], | |
| 217 | 217 | url, | |
| 218 | 218 | }); | |
| 219 | - // TODO: Use handshake response data from undici diagnostics when available. | ||
| 220 | - // https://github.com/nodejs/undici/pull/4396 | ||
| 221 | 219 | Network.webSocketHandshakeResponseReceived({ | |
| 222 | 220 | requestId: websocket[kInspectorRequestId], | |
| 223 | 221 | timestamp: getMonotonicTime(), | |
| 224 | - response: { | ||
| 225 | - status: 101, | ||
| 226 | - statusText: 'Switching Protocols', | ||
| 227 | - headers: {}, | ||
| 228 | - }, | ||
| 222 | + response: handshakeResponse, | ||
| 229 | 223 | }); | |
| 230 | 224 | } | |
| 231 | 225 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,10 +9,12 @@ class WebSocketServer { | |||
| 9 | 9 | constructor({ | |
| 10 | 10 | port = 0, | |
| 11 | 11 | server, | |
| 12 | + customHandleUpgradeHeaders = [], | ||
| 12 | 13 | }) { | |
| 13 | 14 | this.port = port; | |
| 14 | 15 | this.server = server || http.createServer(); | |
| 15 | 16 | this.clients = new Set(); | |
| 17 | + this.customHandleUpgradeHeaders = customHandleUpgradeHeaders; | ||
| 16 | 18 | ||
| 17 | 19 | this.server.on('upgrade', this.handleUpgrade.bind(this)); | |
| 18 | 20 | } | |
@@ -36,6 +38,7 @@ class WebSocketServer { | |||
| 36 | 38 | 'Upgrade: websocket', | |
| 37 | 39 | 'Connection: Upgrade', | |
| 38 | 40 | `Sec-WebSocket-Accept: ${acceptKey}`, | |
| 41 | + ...this.customHandleUpgradeHeaders, | ||
| 39 | 42 | ]; | |
| 40 | 43 | ||
| 41 | 44 | socket.write(responseHeaders.join('\r\n') + '\r\n\r\n'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,8 +29,15 @@ function findFrameInInitiator(regex, initiator) { | |||
| 29 | 29 | ||
| 30 | 30 | async function test() { | |
| 31 | 31 | await session.post('Network.enable'); | |
| 32 | + | ||
| 33 | + const CUSTOM_HEADER_NAME = 'X-Custom-Header'; | ||
| 34 | + const CUSTOM_HEADER_VALUE = 'CustomHeaderValue'; | ||
| 35 | + | ||
| 32 | 36 | const server = new WebSocketServer({ | |
| 33 | 37 | responseError: true, | |
| 38 | + customHandleUpgradeHeaders: [ | ||
| 39 | + `${CUSTOM_HEADER_NAME}: ${CUSTOM_HEADER_VALUE}`, | ||
| 40 | + ] | ||
| 34 | 41 | }); | |
| 35 | 42 | await server.start(); | |
| 36 | 43 | const url = `ws://127.0.0.1:${server.port}/`; | |
@@ -49,6 +56,11 @@ async function test() { | |||
| 49 | 56 | assert.strictEqual(message.params.requestId, requestId); | |
| 50 | 57 | assert.strictEqual(message.params.response.status, 101); | |
| 51 | 58 | assert.strictEqual(message.params.response.statusText, 'Switching Protocols'); | |
| 59 | + assert.strictEqual(message.params.response.headers.upgrade, 'websocket'); | ||
| 60 | + assert.strictEqual(message.params.response.headers.connection, 'Upgrade'); | ||
| 61 | + assert.ok(message.params.response.headers['sec-websocket-accept']); | ||
| 62 | + assert.ok(message.params.response.headers['sec-websocket-accept'].length > 0); | ||
| 63 | + assert.strictEqual(message.params.response.headers[CUSTOM_HEADER_NAME.toLowerCase()], CUSTOM_HEADER_VALUE); | ||
| 52 | 64 | assert.strictEqual(typeof message.params.timestamp, 'number'); | |
| 53 | 65 | socket.close(); | |
| 54 | 66 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments