emitting proxySocket on proxyServer

- emitted once proxySocket was created and socket was piped into it
- needed to support sniffing messages coming from proxy target
This commit is contained in:
Thorsten Lorenz 2014-09-28 22:26:39 -04:00
parent 2aa3b84d7b
commit 000eb533de
2 changed files with 9 additions and 0 deletions

View File

@ -190,6 +190,7 @@ 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.
```js
var httpProxy = require('http-proxy');
@ -220,6 +221,13 @@ proxy.on('proxyRes', function (proxyRes, req, res) {
console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
});
//
// Listen for the `proxySocket` event on `proxy`.
//
proxy.on('proxySocket', function (proxySocket) {
// listen for messages coming FROM the target here
proxySocket.on('data', hybiParseAndLogMessage);
});
```
#### Using HTTPS

View File

@ -108,6 +108,7 @@ var passes = exports;
return i + ": " + proxyRes.headers[i];
}).join('\r\n') + '\r\n\r\n');
proxySocket.pipe(socket).pipe(proxySocket);
server.emit('proxySocket', proxySocket);
});
return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT