AspNetCore.Proxy icon indicating copy to clipboard operation
AspNetCore.Proxy copied to clipboard

WebSocket traffic interception support

Open ferenc-a opened this issue 1 year ago • 5 comments

It's possible to intercept the HTTP to WebSocket upgrade message (https://github.com/twitchax/AspNetCore.Proxy/issues/27#issuecomment-2371760613), but not the traffic afterwards. It would be nice to have the functionality (like for example, here: https://github.com/joeferner/node-http-mitm-proxy/tree/master?tab=readme-ov-file#proxy_onWebSocketConnection). If full support would take too much, at least the WebSocket made by the library should be exposed, or there should be another callback that is provided to library users where they can access it momentarily, before it's fully initialized.

ferenc-a avatar Sep 24 '24 17:09 ferenc-a

@ferenc-a, what is your use case? Curious which approach may be more useful.

twitchax avatar Sep 24 '24 18:09 twitchax

I'd like to parse the messages, modify them, and conditionally inject more inbetween them.

ferenc-a avatar Sep 24 '24 19:09 ferenc-a

Ok, just pushed a commit for this. Would this work for your purposes? Can you try it out?

twitchax avatar Sep 26 '24 22:09 twitchax

I'm going on vacation soon, so it might be more than a week until I can try it sorry. The code looks promising for modifying a message. However, I also want to inject new messages, not just modify existing ones. (Like the equivalent of inject.websocket here: https://docs.mitmproxy.org/stable/addons/examples/#websocket-inject-message).

ferenc-a avatar Sep 27 '24 11:09 ferenc-a

Hey, @twitchax! Could you please make a nuget release that includes WithDataIntercept? It would be very helpful, even as is. Also, did I understand correctly that this doesn't support injecting or removing additional messages, only modifying existing ones?

ferenc-a avatar Nov 18 '25 11:11 ferenc-a