Skip to content

Commit c62610e

Browse files
Jorge Lealjcrugzz
Jorge Leal
authored andcommitted
Deprecated proxySocket event in favor to open event.
Maintained both proxySocket and open for backward compatibility. Conflicts: test/lib-http-proxy-test.js
1 parent 05d18a4 commit c62610e

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ http.createServer(function (req, res) {
195195

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

201202
```js
202203
var httpProxy = require('http-proxy');
@@ -228,9 +229,9 @@ proxy.on('proxyRes', function (proxyRes, req, res) {
228229
});
229230

230231
//
231-
// Listen for the `proxySocket` event on `proxy`.
232+
// Listen for the `open` event on `proxy`.
232233
//
233-
proxy.on('proxySocket', function (proxySocket) {
234+
proxy.on('open', function (proxySocket) {
234235
// listen for messages coming FROM the target here
235236
proxySocket.on('data', hybiParseAndLogMessage);
236237
});

lib/http-proxy/passes/ws-incoming.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ var passes = exports;
118118
return i + ": " + proxyRes.headers[i];
119119
}).join('\r\n') + '\r\n\r\n');
120120
proxySocket.pipe(socket).pipe(proxySocket);
121-
// Make sure server exists before we try to emit
122-
server && server.emit('proxySocket', proxySocket);
121+
122+
server.emit('open', proxySocket);
123+
server.emit('proxySocket', proxySocket); //DEPRECATED.
123124
});
124125

125126
return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT

test/lib-http-proxy-test.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe('lib/http-proxy.js', function() {
280280
client.on('open', function () {
281281
client.send('hello there');
282282
});
283-
283+
284284
var count = 0;
285285
function maybe_done () {
286286
count += 1;
@@ -373,7 +373,7 @@ describe('lib/http-proxy.js', function() {
373373
});
374374

375375

376-
it('should emit close event when socket.io client disconnects', function (done) {
376+
it('should emit open and close events when socket.io client connects and disconnects', function (done) {
377377
var ports = { source: gen.port, proxy: gen.port };
378378
var proxy = httpProxy.createProxyServer({
379379
target: 'ws://127.0.0.1:' + ports.source,
@@ -389,11 +389,17 @@ describe('lib/http-proxy.js', function() {
389389
client.disconnect();
390390
});
391391
}
392-
392+
var count = 0;
393+
394+
proxyServer.on('open', function() {
395+
count += 1;
396+
397+
});
398+
393399
proxyServer.on('close', function() {
394400
proxyServer.close();
395401
server.close();
396-
done();
402+
if (count == 1) { done(); }
397403
});
398404

399405
server.listen(ports.source);

0 commit comments

Comments
 (0)