mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
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:
parent
05d18a4e1b
commit
c62610e8e4
@ -195,8 +195,9 @@ http.createServer(function (req, res) {
|
|||||||
|
|
||||||
* `error`: The error event is emitted if the request to the target fail.
|
* `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.
|
* `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.
|
* `close`: This event is emitted once the proxy websocket was closed.
|
||||||
|
* (DEPRECATED) `proxySocket`: Deprecated in favor to `open`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var httpProxy = require('http-proxy');
|
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
|
// listen for messages coming FROM the target here
|
||||||
proxySocket.on('data', hybiParseAndLogMessage);
|
proxySocket.on('data', hybiParseAndLogMessage);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -118,8 +118,9 @@ var passes = exports;
|
|||||||
return i + ": " + proxyRes.headers[i];
|
return i + ": " + proxyRes.headers[i];
|
||||||
}).join('\r\n') + '\r\n\r\n');
|
}).join('\r\n') + '\r\n\r\n');
|
||||||
proxySocket.pipe(socket).pipe(proxySocket);
|
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
|
return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT
|
||||||
|
|||||||
@ -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 ports = { source: gen.port, proxy: gen.port };
|
||||||
var proxy = httpProxy.createProxyServer({
|
var proxy = httpProxy.createProxyServer({
|
||||||
target: 'ws://127.0.0.1:' + ports.source,
|
target: 'ws://127.0.0.1:' + ports.source,
|
||||||
@ -389,11 +389,17 @@ describe('lib/http-proxy.js', function() {
|
|||||||
client.disconnect();
|
client.disconnect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
proxyServer.on('open', function() {
|
||||||
|
count += 1;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
proxyServer.on('close', function() {
|
proxyServer.on('close', function() {
|
||||||
proxyServer.close();
|
proxyServer.close();
|
||||||
server.close();
|
server.close();
|
||||||
done();
|
if (count == 1) { done(); }
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(ports.source);
|
server.listen(ports.source);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user