Deprecated proxySocket event in favor to open event.

Maintained both proxySocket and open for backward compatibility.

Conflicts:
	test/lib-http-proxy-test.js
This commit is contained in:
Jorge Leal 2014-12-11 20:47:22 +01:00 committed by Jarrett Cruger
parent 05d18a4e1b
commit c62610e8e4
3 changed files with 17 additions and 9 deletions

View File

@ -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');
@ -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);
});

View File

@ -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

View File

@ -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,
@ -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);