diff --git a/README.md b/README.md index a147a37cf..1943f3f30 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index 7673fe067..8c05e32e8 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -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