Skip to content

Commit 9210b56

Browse files
committed
Merge pull request #706 from thlorenz/expose-proxy-socket
exposing proxySocket on socket to support sniffing messages coming from proxy target
2 parents 2aa3b84 + 000eb53 commit 9210b56

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ http.createServer(function (req, res) {
190190

191191
* `error`: The error event is emitted if the request to the target fail.
192192
* `proxyRes`: This event is emitted if the request to the target got a response.
193+
* `proxySocket`: This event is emitted once the proxy websocket was created and piped into the target websocket.
193194

194195
```js
195196
var httpProxy = require('http-proxy');
@@ -220,6 +221,13 @@ proxy.on('proxyRes', function (proxyRes, req, res) {
220221
console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
221222
});
222223

224+
//
225+
// Listen for the `proxySocket` event on `proxy`.
226+
//
227+
proxy.on('proxySocket', function (proxySocket) {
228+
// listen for messages coming FROM the target here
229+
proxySocket.on('data', hybiParseAndLogMessage);
230+
});
223231
```
224232

225233
#### Using HTTPS

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

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ var passes = exports;
108108
return i + ": " + proxyRes.headers[i];
109109
}).join('\r\n') + '\r\n\r\n');
110110
proxySocket.pipe(socket).pipe(proxySocket);
111+
server.emit('proxySocket', proxySocket);
111112
});
112113

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

0 commit comments

Comments
 (0)