twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
529 stars 83 forks source link

WebSocket traffic interception support #121

Open ferenc-a opened 1 month ago

ferenc-a commented 1 month ago

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.

twitchax commented 1 month ago

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

ferenc-a commented 1 month ago

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

twitchax commented 1 month ago

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

ferenc-a commented 1 month ago

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).