@@ -394,6 +394,19 @@ export class PassThroughWebSocketHandler extends PassThroughWebSocketHandlerDefi
394
394
395
395
if ( options . emitEventCallback ) {
396
396
const upstreamReq = ( upstreamWebSocket as any as { _req : http . ClientRequest } ) . _req ;
397
+ // This is slower than req.getHeaders(), but gives us (roughly) the correct casing
398
+ // of the headers as sent. Still not perfect (loses dupe ordering) but at least it
399
+ // generally matches what's actually sent on the wire.
400
+ const rawHeaders = upstreamReq . getRawHeaderNames ( ) . map ( ( headerName ) => {
401
+ const value = upstreamReq . getHeader ( headerName ) ;
402
+ if ( ! value ) return [ ] ;
403
+ if ( Array . isArray ( value ) ) {
404
+ return value . map ( v => [ headerName , v ] ) ;
405
+ } else {
406
+ return [ [ headerName , value . toString ( ) ] ] ;
407
+ }
408
+ } ) . flat ( ) as RawHeaders ;
409
+
397
410
options . emitEventCallback ( 'passthrough-websocket-connect' , {
398
411
method : upstreamReq . method ,
399
412
protocol : upstreamReq . protocol
@@ -402,7 +415,7 @@ export class PassThroughWebSocketHandler extends PassThroughWebSocketHandlerDefi
402
415
hostname : upstreamReq . host ,
403
416
port : effectivePort . toString ( ) ,
404
417
path : upstreamReq . path ,
405
- rawHeaders : objectHeadersToRaw ( upstreamReq . getHeaders ( ) as Headers ) ,
418
+ rawHeaders : rawHeaders ,
406
419
subprotocols : filteredSubprotocols
407
420
} ) ;
408
421
}
0 commit comments