25
25
*/
26
26
27
27
var events = require ( 'events' ) ,
28
+ http = require ( 'http' ) ,
28
29
util = require ( 'util' ) ,
29
30
httpProxy = require ( '../node-http-proxy' ) ;
30
31
@@ -594,6 +595,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
594
595
outgoing . method = 'GET' ;
595
596
outgoing . path = req . url ;
596
597
outgoing . headers = req . headers ;
598
+ outgoing . agent = agent ;
597
599
598
600
var reverseProxy = this . target . protocol . request ( outgoing ) ;
599
601
@@ -617,7 +619,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
617
619
// available to the `upgrade` event. This bookkeeping is not tracked anywhere
618
620
// in nodejs core and is **very** specific to proxying WebSockets.
619
621
//
620
- reverseProxy . agent = agent ;
621
622
reverseProxy . incoming = {
622
623
request : req ,
623
624
socket : socket ,
@@ -632,17 +633,15 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
632
633
// In addition, it's important to note the closure scope here. Since
633
634
// there is no mapping of the socket to the request bound to it.
634
635
//
635
- if ( ! agent . _events || agent . _events [ 'upgrade' ] . length === 0 ) {
636
- agent . on ( 'upgrade' , function ( _ , remoteSocket , head ) {
637
- //
638
- // Prepare the socket for the reverseProxy request and begin to
639
- // stream data between the two sockets. Here it is important to
640
- // note that `remoteSocket._httpMessage === reverseProxy`.
641
- //
642
- _socket ( remoteSocket , true ) ;
643
- onUpgrade ( remoteSocket . _httpMessage , remoteSocket ) ;
644
- } ) ;
645
- }
636
+ reverseProxy . on ( 'upgrade' , function ( _ , remoteSocket , head ) {
637
+ //
638
+ // Prepare the socket for the reverseProxy request and begin to
639
+ // stream data between the two sockets. Here it is important to
640
+ // note that `remoteSocket._httpMessage === reverseProxy`.
641
+ //
642
+ _socket ( remoteSocket , true ) ;
643
+ onUpgrade ( remoteSocket . _httpMessage , remoteSocket ) ;
644
+ } ) ;
646
645
647
646
//
648
647
// If the reverseProxy connection has an underlying socket,
0 commit comments