feat(websocket): add handshake response info to undici:websocket:open diagnostic event#4396
Conversation
… diagnostic event - Add handshakeResponse object to undici:websocket:open diagnostic event - Include status, statusText, and headers from HTTP handshake response - Enables Chrome DevTools Protocol Network.webSocketHandshakeResponseReceived support - Add comprehensive test coverage for handshake response diagnostic data Fixes nodejs#4394
…diagnostics channel event emission - Fixes diagnostics channel WebSocket event emission and related test timeouts in Node.js 20+. - Cleans up debug/test scripts and logs.
… redundant checks, and improve handshake header assertions in test
lib/web/websocket/websocket.js
Outdated
|
|
||
| if (channels.open.hasSubscribers) { | ||
| // Convert headers to a plain object for the event | ||
| const headers = Object.fromEntries(response.headersList.headersMap.entries()) |
There was a problem hiding this comment.
| const headers = Object.fromEntries(response.headersList.headersMap.entries()) | |
| const headers = response.headersList.entries |
There was a problem hiding this comment.
In the current undici version, response.headersList does not have an entries property that is a plain object of headers. Instead, it has a headersMap property (which is a Map), so to get a plain object of headers, we need to use:
const headers = Object.fromEntries(response.headersList.headersMap.entries())
Assigning const headers = response.headersList.entries would not work here, as it would result in a function (or undefined), not the actual headers object.
If the structure of headersList changes in the future to expose a plain object or a suitable entries property, we can update this logic accordingly.
…ders - Replace Object.fromEntries(response.headersList.headersMap.entries()) with response.headersList.entries - Use the built-in getter method from HeadersList class for cleaner, more efficient code - Update test to match new plain object format (remove .value property access) - Fix test plan count to match actual number of assertions (11) Addresses KhafraDev's code review feedback to use the purpose-built entries getter.
|
Could you add this to diagnostics channel's documentation? https://github.com/nodejs/undici/blob/main/docs/docs/api/DiagnosticsChannel.md |
- Add handshakeResponse object documentation to DiagnosticsChannel.md - Remove console.log statements from test file - Fix linting issues in test file
Fixes #4394
Status