Commit 56003b52 authored by Fedor Indutny's avatar Fedor Indutny

Added support of automatic websocket tunneling, added test for it

parent cd78af5f
...@@ -60,9 +60,17 @@ exports.createServer = function () { ...@@ -60,9 +60,17 @@ exports.createServer = function () {
} }
}); });
// WebSocket support // If callback is empty - tunnel websocket request automatically
server.on('update', function() { 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; return server;
}; };
...@@ -325,12 +333,12 @@ HttpProxy.prototype = { ...@@ -325,12 +333,12 @@ HttpProxy.prototype = {
request.end(); request.end();
socket.end(); socket.end();
} }
// Catch socket errors // Catch socket errors
socket.on('error', function() { socket.on('error', function() {
request.end(); request.end();
}); });
// Remove data listener // Remove data listener
request.socket.removeListener('data', t); request.socket.removeListener('data', t);
}); });
...@@ -344,7 +352,7 @@ HttpProxy.prototype = { ...@@ -344,7 +352,7 @@ HttpProxy.prototype = {
} }
self.unwatch(socket); self.unwatch(socket);
}); });
// Request // Request
function onUpgrade(reverse_proxy) { function onUpgrade(reverse_proxy) {
......
...@@ -48,4 +48,7 @@ server.on('upgrade', function(req, socket, head) { ...@@ -48,4 +48,7 @@ server.on('upgrade', function(req, socket, head) {
p.proxyWebSocketRequest(8080, 'localhost'); p.proxyWebSocketRequest(8080, 'localhost');
}); });
server.listen(80); server.listen(8000);
httpProxy.createServer(8080, 'localhost').listen(8001);
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