Skip to content

Conversation

tawseefnabi
Copy link
Contributor

@tawseefnabi tawseefnabi commented Aug 8, 2025

  • 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 #4394

Status

… 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.
@tawseefnabi tawseefnabi requested a review from tsctx August 8, 2025 15:06
… redundant checks, and improve handshake header assertions in test
@tawseefnabi tawseefnabi requested a review from KhafraDev August 8, 2025 16:05

if (channels.open.hasSubscribers) {
// Convert headers to a plain object for the event
const headers = Object.fromEntries(response.headersList.headersMap.entries())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const headers = Object.fromEntries(response.headersList.headersMap.entries())
const headers = response.headersList.entries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get entries () {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tawseefnabi tawseefnabi requested a review from KhafraDev August 8, 2025 16:52
…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.
@tsctx
Copy link
Member

tsctx commented Aug 9, 2025

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
@tawseefnabi tawseefnabi requested a review from tsctx August 9, 2025 07:37
@tawseefnabi tawseefnabi requested a review from tsctx August 9, 2025 07:41
@tsctx tsctx merged commit e5bf00e into nodejs:main Aug 9, 2025
22 of 27 checks passed
@github-actions github-actions bot mentioned this pull request Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add handshake response info to undici:websocket:open diagnostic event
3 participants