File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Open diff view settings
Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -209,23 +209,17 @@ function onClientResponseFinish({ request }) {
209209// TODO: Move Network.webSocketCreated to the actual creation time of the WebSocket.
210210// undici:websocket:open fires when the connection is established, but this results
211211// in an inaccurate stack trace.
212- function onWebSocketOpen ( { websocket } ) {
212+ function onWebSocketOpen ( { websocket, handshakeResponse } ) {
213213 websocket [ kInspectorRequestId ] = getNextRequestId ( ) ;
214214 const url = websocket . url . toString ( ) ;
215215 Network . webSocketCreated ( {
216216 requestId : websocket [ kInspectorRequestId ] ,
217217 url,
218218 } ) ;
219- // TODO: Use handshake response data from undici diagnostics when available.
220- // https://github.com/nodejs/undici/pull/4396
221219 Network . webSocketHandshakeResponseReceived ( {
222220 requestId : websocket [ kInspectorRequestId ] ,
223221 timestamp : getMonotonicTime ( ) ,
224- response : {
225- status : 101 ,
226- statusText : 'Switching Protocols' ,
227- headers : { } ,
228- } ,
222+ response : handshakeResponse ,
229223 } ) ;
230224}
231225
Original file line number Diff line number Diff line change @@ -9,10 +9,12 @@ class WebSocketServer {
99 constructor ( {
1010 port = 0 ,
1111 server,
12+ customHandleUpgradeHeaders = [ ] ,
1213 } ) {
1314 this . port = port ;
1415 this . server = server || http . createServer ( ) ;
1516 this . clients = new Set ( ) ;
17+ this . customHandleUpgradeHeaders = customHandleUpgradeHeaders ;
1618
1719 this . server . on ( 'upgrade' , this . handleUpgrade . bind ( this ) ) ;
1820 }
@@ -36,6 +38,7 @@ class WebSocketServer {
3638 'Upgrade: websocket' ,
3739 'Connection: Upgrade' ,
3840 `Sec-WebSocket-Accept: ${ acceptKey } ` ,
41+ ...this . customHandleUpgradeHeaders ,
3942 ] ;
4043
4144 socket . write ( responseHeaders . join ( '\r\n' ) + '\r\n\r\n' ) ;
Original file line number Diff line number Diff line change @@ -29,8 +29,15 @@ function findFrameInInitiator(regex, initiator) {
2929
3030async function test ( ) {
3131 await session . post ( 'Network.enable' ) ;
32+
33+ const CUSTOM_HEADER_NAME = 'X-Custom-Header' ;
34+ const CUSTOM_HEADER_VALUE = 'CustomHeaderValue' ;
35+
3236 const server = new WebSocketServer ( {
3337 responseError : true ,
38+ customHandleUpgradeHeaders : [
39+ `${ CUSTOM_HEADER_NAME } : ${ CUSTOM_HEADER_VALUE } ` ,
40+ ]
3441 } ) ;
3542 await server . start ( ) ;
3643 const url = `ws://127.0.0.1:${ server . port } /` ;
@@ -49,6 +56,11 @@ async function test() {
4956 assert . strictEqual ( message . params . requestId , requestId ) ;
5057 assert . strictEqual ( message . params . response . status , 101 ) ;
5158 assert . strictEqual ( message . params . response . statusText , 'Switching Protocols' ) ;
59+ assert . strictEqual ( message . params . response . headers . upgrade , 'websocket' ) ;
60+ assert . strictEqual ( message . params . response . headers . connection , 'Upgrade' ) ;
61+ assert . ok ( message . params . response . headers [ 'sec-websocket-accept' ] ) ;
62+ assert . ok ( message . params . response . headers [ 'sec-websocket-accept' ] . length > 0 ) ;
63+ assert . strictEqual ( message . params . response . headers [ CUSTOM_HEADER_NAME . toLowerCase ( ) ] , CUSTOM_HEADER_VALUE ) ;
5264 assert . strictEqual ( typeof message . params . timestamp , 'number' ) ;
5365 socket . close ( ) ;
5466 } ) ) ;
You can’t perform that action at this time.
0 commit comments