@@ -496,6 +496,11 @@ class ConfigurableProxy extends EventEmitter {
496
496
handleProxy ( kind , req , res ) {
497
497
// proxy any request
498
498
var that = this ;
499
+
500
+ // handleProxy is invoked by handleProxyWeb and handleProxyWs, which pass
501
+ // different arguments to handleProxy.
502
+ // - handleProxyWeb: args = [req, res]
503
+ // - handleProxyWs: args = [req, socket, head]
499
504
var args = Array . prototype . slice . call ( arguments , 1 ) ;
500
505
501
506
// get the proxy target
@@ -505,7 +510,12 @@ class ConfigurableProxy extends EventEmitter {
505
510
return ;
506
511
}
507
512
508
- that . emit ( "proxyRequest" , req , res ) ;
513
+ if ( kind === "web" ) {
514
+ that . emit ( "proxyRequest" , req , res ) ;
515
+ }
516
+ else {
517
+ that . emit ( "proxyRequestWs" , req , res , args [ 2 ] ) ;
518
+ }
509
519
var prefix = match . prefix ;
510
520
var target = match . target ;
511
521
that . log . debug ( "PROXY %s %s to %s" , kind . toUpperCase ( ) , req . url , target ) ;
@@ -528,7 +538,9 @@ class ConfigurableProxy extends EventEmitter {
528
538
that . handleProxyError ( 503 , kind , req , res , e ) ;
529
539
} ) ;
530
540
531
- // dispatch the actual method
541
+ // dispatch the actual method, either:
542
+ // - proxy.web(req, res, options, errorHandler)
543
+ // - proxy.ws(req, socket, head, options, errorHandler)
532
544
that . proxy [ kind ] . apply ( that . proxy , args ) ;
533
545
534
546
// update timestamp on any request/reply data as well (this includes websocket data)
@@ -545,10 +557,10 @@ class ConfigurableProxy extends EventEmitter {
545
557
} ) ;
546
558
}
547
559
548
- handleProxyWs ( req , res , head ) {
560
+ handleProxyWs ( req , socket , head ) {
549
561
// Proxy a websocket request
550
562
this . statsd . increment ( "requests.ws" , 1 ) ;
551
- return this . handleProxy ( "ws" , req , res , head ) ;
563
+ return this . handleProxy ( "ws" , req , socket , head ) ;
552
564
}
553
565
554
566
handleProxyWeb ( req , res ) {
0 commit comments