-
-
Notifications
You must be signed in to change notification settings - Fork 666
feat(websocket): add handshake response info to undici:websocket:open diagnostic event #4396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const headers = Object.fromEntries(response.headersList.headersMap.entries()) | |
const headers = response.headersList.entries |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undici/lib/web/fetch/headers.js
Line 318 in c3f5591
get entries () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…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