feat(websocket): add handshake response info to undici:websocket:open diagnostic event#4396
Merged
tsctx merged 6 commits intonodejs:mainfrom Aug 9, 2025
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
tsctx
reviewed
Aug 8, 2025
…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.
KhafraDev
requested changes
Aug 8, 2025
… redundant checks, and improve handshake header assertions in test
KhafraDev
requested changes
Aug 8, 2025
|
|
||
| if (channels.open.hasSubscribers) { | ||
| // Convert headers to a plain object for the event | ||
| const headers = Object.fromEntries(response.headersList.headersMap.entries()) |
Member
There was a problem hiding this comment.
Suggested change
| const headers = Object.fromEntries(response.headersList.headersMap.entries()) | |
| const headers = response.headersList.entries |
Contributor
Author
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.
KhafraDev
approved these changes
Aug 9, 2025
tsctx
reviewed
Aug 9, 2025
Member
|
Could you add this to diagnostics channel's documentation? |
- Add handshakeResponse object documentation to DiagnosticsChannel.md - Remove console.log statements from test file - Fix linting issues in test file
tsctx
reviewed
Aug 9, 2025
tsctx
approved these changes
Aug 9, 2025
Merged
slagiewka
pushed a commit
to slagiewka/undici
that referenced
this pull request
Feb 14, 2026
… diagnostic event (nodejs#4396) * feat(websocket): add handshake response info to undici:websocket:open 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 * fix(websocket/diagnostics): use headersList.headersMap.entries() for 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. * fix(websocket/diagnostics): clean up after review, remove debug logs, redundant checks, and improve handshake header assertions in test * refactor: use HeadersList.entries getter for WebSocket diagnostic headers - 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. * docs: document handshakeResponse in websocket:open diagnostics - Add handshakeResponse object documentation to DiagnosticsChannel.md - Remove console.log statements from test file - Fix linting issues in test file * test: remove console.log and mark unused WebSocket variable --------- Co-authored-by: tawseefnabi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4394
Status