-
-
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
Merged
tsctx
merged 6 commits into
nodejs:main
from
tawseefnabi:feat/websocket-handshake-response-diagnostic
Aug 9, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f87dbf
feat(websocket): add handshake response info to undici:websocket:open…
5f68c38
fix(websocket/diagnostics): use headersList.headersMap.entries() for …
92f6fcc
fix(websocket/diagnostics): clean up after review, remove debug logs,…
766e853
refactor: use HeadersList.entries getter for WebSocket diagnostic hea…
814e102
docs: document handshakeResponse in websocket:open diagnostics
e62a78a
test: remove console.log and mark unused WebSocket variable
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict' | ||
|
||
const { test } = require('node:test') | ||
const dc = require('node:diagnostics_channel') | ||
const { WebSocketServer } = require('ws') | ||
const { WebSocket } = require('../..') | ||
const { tspl } = require('@matteo.collina/tspl') | ||
|
||
test('diagnostics channel - undici:websocket:open includes handshake response', async (t) => { | ||
const { equal, ok, completed } = tspl(t, { plan: 11 }) | ||
|
||
const server = new WebSocketServer({ port: 0 }) | ||
const { port } = server.address() | ||
|
||
server.on('connection', (ws) => { | ||
setTimeout(() => { | ||
ws.close(1000, 'test') | ||
}, 50) | ||
}) | ||
|
||
const openListener = (data) => { | ||
// Verify handshake response data | ||
ok(data.handshakeResponse, 'handshakeResponse should be defined') | ||
equal(data.handshakeResponse.status, 101, 'status should be 101') | ||
equal(data.handshakeResponse.statusText, 'Switching Protocols', 'statusText should be correct') | ||
KhafraDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Check handshake response headers | ||
const headers = data.handshakeResponse.headers | ||
ok(headers, 'headers should be defined') | ||
ok(typeof headers === 'object', 'headers should be an object') | ||
ok('upgrade' in headers, 'upgrade header should be present') | ||
ok('connection' in headers, 'connection header should be present') | ||
ok('sec-websocket-accept' in headers, 'sec-websocket-accept header should be present') | ||
// Optionally, check values | ||
equal(headers.upgrade.toLowerCase(), 'websocket', 'upgrade header should be websocket') | ||
equal(headers.connection.toLowerCase(), 'upgrade', 'connection header should be upgrade') | ||
ok(typeof headers['sec-websocket-accept'] === 'string', 'sec-websocket-accept header should be a string') | ||
} | ||
|
||
dc.channel('undici:websocket:open').subscribe(openListener) | ||
|
||
t.after(() => { | ||
server.close() | ||
dc.channel('undici:websocket:open').unsubscribe(openListener) | ||
}) | ||
|
||
// Create WebSocket connection | ||
// eslint-disable-next-line no-unused-vars | ||
const _ws = new WebSocket(`ws://localhost:${port}`) | ||
|
||
await completed | ||
}) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.