Skip to content

Commit

Permalink
emitting proxySocket on proxyServer
Browse files Browse the repository at this point in the history
- emitted once proxySocket was created and socket was piped into it
- needed to support sniffing messages coming from proxy target
  • Loading branch information
thlorenz committed Sep 30, 2014
1 parent 2aa3b84 commit 000eb53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/http-proxy/passes/ws-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 000eb53

Please sign in to comment.