@@ -541,21 +541,10 @@ export class Tunnel {
541541 // Store adapter
542542 this . #actorWebSockets. set ( webSocketId , adapter ) ;
543543
544- // Send open confirmation
545- let hibernationConfig = this . #runner. config . getActorHibernationConfig ( actor . actorId , requestId ) ;
546- this . #sendMessage( requestId , {
547- tag : "ToServerWebSocketOpen" ,
548- val : {
549- canHibernate : hibernationConfig . enabled ,
550- lastMsgIndex : BigInt ( hibernationConfig . lastMsgIndex ?? - 1 ) ,
551- } ,
552- } ) ;
553-
554- // Notify adapter that connection is open
555- adapter . _handleOpen ( requestId ) ;
556-
557- // Create a minimal request object for the websocket handler
558- // Include original headers from the open message
544+ // Convert headers to map
545+ //
546+ // We need to manually ensure the original Upgrade/Connection WS
547+ // headers are present
559548 const headerInit : Record < string , string > = { } ;
560549 if ( open . headers ) {
561550 for ( const [ k , v ] of open . headers as ReadonlyMap <
@@ -565,7 +554,6 @@ export class Tunnel {
565554 headerInit [ k ] = v ;
566555 }
567556 }
568- // Ensure websocket upgrade headers are present
569557 headerInit [ "Upgrade" ] = "websocket" ;
570558 headerInit [ "Connection" ] = "Upgrade" ;
571559
@@ -574,6 +562,21 @@ export class Tunnel {
574562 headers : headerInit ,
575563 } ) ;
576564
565+ // Send open confirmation
566+ let hibernationConfig = this . #runner. config . getActorHibernationConfig ( actor . actorId , requestId , request ) ;
567+ this . #sendMessage( requestId , {
568+ tag : "ToServerWebSocketOpen" ,
569+ val : {
570+ canHibernate : hibernationConfig . enabled ,
571+ lastMsgIndex : BigInt ( hibernationConfig . lastMsgIndex ?? - 1 ) ,
572+ } ,
573+ } ) ;
574+
575+ // Notify adapter that connection is open
576+ adapter . _handleOpen ( requestId ) ;
577+
578+
579+
577580 // Call websocket handler
578581 await websocketHandler (
579582 this . #runner,
0 commit comments