http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.86k stars 1.96k forks source link

Modifying the websocket sent message #1203

Open conradkao opened 6 years ago

conradkao commented 6 years ago

I created a proxy to redirect websocket connections to another websocket server like: websocket client <-----> proxy <-----> websocket target server

In order to control the messages that sent from client to the sever, I would like to know what messages are sent to the server and do some filtering. I found the following codes helping me to get the sent messages but I can't filter the unwanted messages (such as 'hello'). Is there another method I can use to add some logic before the messages are sent to target server ?

proxy.on('proxyReqWs', function(proxyReq, req, socket, res, options) { var parser = new WsParser(0, false); socket.pipe(parser); parser.on('frame', function (frame) { // handle the frame console.log('Up:',frame); console.log('Up data:'+frame.data); });
});

thjaeckle commented 5 years ago

@conradkao did you ever manage to get this working? I want to do the same and only got it working logging the websocket frames..