Skip to content

Added ability to intercept and manipulate web socket messages#991

Open
RoscoP wants to merge 2 commits intohttp-party:masterfrom
RoscoP:websocket-intercept-msg
Open

Added ability to intercept and manipulate web socket messages#991
RoscoP wants to merge 2 commits intohttp-party:masterfrom
RoscoP:websocket-intercept-msg

Conversation

@RoscoP
Copy link
Copy Markdown

@RoscoP RoscoP commented Apr 19, 2016

I offer this PR up in case this functionality is desired for node-http-proxy - I needed this ability, but couldn't find it anywhere and thought someone else might find it useful. Thanks for the solid code.

I've isolated this ability away from the normal proxy behavior. If you set wsInterceptMessages to true in the options then it will intercept and relay websocket messages.

In options:
wsOnMessageToServer - Is a function called when a message is intercepted on its way to the server. It takes two arguments: data is a websocket message in a Buffer class, and flags describe the message (compressed, binary, etc - from the websocket ws/lib/Receiver and Sender classes. This function is expected to return a buffer that is to be used for the websocket message. If null is returned, the message is consumed and nothing will be forwarded along the websocket proxy.
wsOnMessageToClient - Is a function called when a message is intercepted on its way to the client. It also takes the same arguments as wsOnMessageToServer

Events:
message_toserver - Emitted on message to server, can be used in place of the functions if you only wish to monitor and not modify the messages.
message_toclient - Same as above for client.
websocket_connected - Emitted when websocket interception setup is complete.

@thjaeckle
Copy link
Copy Markdown

Any chance that this will be merged some day?
Would also really need this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants