mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Added support of automatic websocket tunneling, added test for it
This commit is contained in:
parent
cd78af5fea
commit
56003b5276
@ -60,9 +60,17 @@ exports.createServer = function () {
|
||||
}
|
||||
});
|
||||
|
||||
// WebSocket support
|
||||
server.on('update', function() {
|
||||
});
|
||||
// If callback is empty - tunnel websocket request automatically
|
||||
if (!callback) {
|
||||
// WebSocket support
|
||||
server.on('upgrade', function(req, socket, head) {
|
||||
var proxy = new HttpProxy(req, socket, head);
|
||||
|
||||
// Tunnel websocket requests too
|
||||
proxy.proxyWebSocketRequest(port, host);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return server;
|
||||
};
|
||||
@ -325,12 +333,12 @@ HttpProxy.prototype = {
|
||||
request.end();
|
||||
socket.end();
|
||||
}
|
||||
|
||||
|
||||
// Catch socket errors
|
||||
socket.on('error', function() {
|
||||
request.end();
|
||||
});
|
||||
|
||||
|
||||
// Remove data listener
|
||||
request.socket.removeListener('data', t);
|
||||
});
|
||||
@ -344,7 +352,7 @@ HttpProxy.prototype = {
|
||||
}
|
||||
self.unwatch(socket);
|
||||
});
|
||||
|
||||
|
||||
// Request
|
||||
|
||||
function onUpgrade(reverse_proxy) {
|
||||
|
||||
@ -48,4 +48,7 @@ server.on('upgrade', function(req, socket, head) {
|
||||
p.proxyWebSocketRequest(8080, 'localhost');
|
||||
});
|
||||
|
||||
server.listen(80);
|
||||
server.listen(8000);
|
||||
|
||||
httpProxy.createServer(8080, 'localhost').listen(8001);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user