Skip to content

Commit 5b52c89

Browse files
indexzerommalecki
authored andcommitted
[refactor] Updates to support http2 from @mikeal
Conflicts: lib/node-http-proxy/http-proxy.js
1 parent 86b4122 commit 5b52c89

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/node-http-proxy/http-proxy.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
var events = require('events'),
28+
http = require('http'),
2829
util = require('util'),
2930
httpProxy = require('../node-http-proxy');
3031

@@ -594,6 +595,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
594595
outgoing.method = 'GET';
595596
outgoing.path = req.url;
596597
outgoing.headers = req.headers;
598+
outgoing.agent = agent;
597599

598600
var reverseProxy = this.target.protocol.request(outgoing);
599601

@@ -617,7 +619,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
617619
// available to the `upgrade` event. This bookkeeping is not tracked anywhere
618620
// in nodejs core and is **very** specific to proxying WebSockets.
619621
//
620-
reverseProxy.agent = agent;
621622
reverseProxy.incoming = {
622623
request: req,
623624
socket: socket,
@@ -632,17 +633,15 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
632633
// In addition, it's important to note the closure scope here. Since
633634
// there is no mapping of the socket to the request bound to it.
634635
//
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+
});
646645

647646
//
648647
// If the reverseProxy connection has an underlying socket,

0 commit comments

Comments
 (0)