Skip to content

Commit

Permalink
Added support of automatic websocket tunneling, added test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Sep 16, 2010
1 parent cd78af5 commit 56003b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
20 changes: 14 additions & 6 deletions lib/node-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
});
Expand All @@ -344,7 +352,7 @@ HttpProxy.prototype = {
}
self.unwatch(socket);
});

// Request

function onUpgrade(reverse_proxy) {
Expand Down
5 changes: 4 additions & 1 deletion test/node-http-proxy-websocket-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 56003b5

Please sign in to comment.