Commit cf39e55a authored by indexzero's avatar indexzero Committed by Cédric de Saint Martin

[refactor] Updates to support http2 from @mikeal

Conflicts:

	lib/node-http-proxy/http-proxy.js
parent 54c2a61b
......@@ -25,6 +25,7 @@
*/
var events = require('events'),
http = require('http'),
util = require('util'),
httpProxy = require('../node-http-proxy');
......@@ -603,6 +604,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
outgoing.method = 'GET';
outgoing.path = req.url;
outgoing.headers = req.headers;
outgoing.agent = agent;
var reverseProxy = this.target.protocol.request(outgoing);
......@@ -626,7 +628,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// available to the `upgrade` event. This bookkeeping is not tracked anywhere
// in nodejs core and is **very** specific to proxying WebSockets.
//
reverseProxy.agent = agent;
reverseProxy.incoming = {
request: req,
socket: socket,
......@@ -641,17 +642,15 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// In addition, it's important to note the closure scope here. Since
// there is no mapping of the socket to the request bound to it.
//
if (!agent._events || agent._events['upgrade'].length === 0) {
agent.on('upgrade', function (_, remoteSocket, head) {
//
// Prepare the socket for the reverseProxy request and begin to
// stream data between the two sockets. Here it is important to
// note that `remoteSocket._httpMessage === reverseProxy`.
//
_socket(remoteSocket, true);
onUpgrade(remoteSocket._httpMessage, remoteSocket);
});
}
reverseProxy.on('upgrade', function (_, remoteSocket, head) {
//
// Prepare the socket for the reverseProxy request and begin to
// stream data between the two sockets. Here it is important to
// note that `remoteSocket._httpMessage === reverseProxy`.
//
_socket(remoteSocket, true);
onUpgrade(remoteSocket._httpMessage, remoteSocket);
});
//
// If the reverseProxy connection has an underlying socket,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment