Skip to content

Commit

Permalink
Deprecated proxySocket event in favor to open event.
Browse files Browse the repository at this point in the history
Maintained both proxySocket and open for backward compatibility.

Conflicts:
	test/lib-http-proxy-test.js
  • Loading branch information
Jorge Leal authored and jcrugzz committed Dec 17, 2014
1 parent 05d18a4 commit c62610e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -195,8 +195,9 @@ http.createServer(function (req, res) {

* `error`: The error event is emitted if the request to the target fail.
* `proxyRes`: This event is emitted if the request to the target got a response.
* `proxySocket`: This event is emitted once the proxy websocket was created and piped into the target websocket.
* `open`: This event is emitted once the proxy websocket was created and piped into the target websocket.
* `close`: This event is emitted once the proxy websocket was closed.
* (DEPRECATED) `proxySocket`: Deprecated in favor to `open`.

```js
var httpProxy = require('http-proxy');
Expand Down Expand Up @@ -228,9 +229,9 @@ proxy.on('proxyRes', function (proxyRes, req, res) {
});

//
// Listen for the `proxySocket` event on `proxy`.
// Listen for the `open` event on `proxy`.
//
proxy.on('proxySocket', function (proxySocket) {
proxy.on('open', function (proxySocket) {
// listen for messages coming FROM the target here
proxySocket.on('data', hybiParseAndLogMessage);
});
Expand Down
5 changes: 3 additions & 2 deletions lib/http-proxy/passes/ws-incoming.js
Expand Up @@ -118,8 +118,9 @@ var passes = exports;
return i + ": " + proxyRes.headers[i];
}).join('\r\n') + '\r\n\r\n');
proxySocket.pipe(socket).pipe(proxySocket);
// Make sure server exists before we try to emit
server && server.emit('proxySocket', proxySocket);

server.emit('open', proxySocket);
server.emit('proxySocket', proxySocket); //DEPRECATED.
});

return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT
Expand Down
14 changes: 10 additions & 4 deletions test/lib-http-proxy-test.js
Expand Up @@ -280,7 +280,7 @@ describe('lib/http-proxy.js', function() {
client.on('open', function () {
client.send('hello there');
});

var count = 0;
function maybe_done () {
count += 1;
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('lib/http-proxy.js', function() {
});


it('should emit close event when socket.io client disconnects', function (done) {
it('should emit open and close events when socket.io client connects and disconnects', function (done) {
var ports = { source: gen.port, proxy: gen.port };
var proxy = httpProxy.createProxyServer({
target: 'ws://127.0.0.1:' + ports.source,
Expand All @@ -389,11 +389,17 @@ describe('lib/http-proxy.js', function() {
client.disconnect();
});
}

var count = 0;

proxyServer.on('open', function() {
count += 1;

});

proxyServer.on('close', function() {
proxyServer.close();
server.close();
done();
if (count == 1) { done(); }
});

server.listen(ports.source);
Expand Down

0 comments on commit c62610e

Please sign in to comment.