Push own WebSocket message

I inspect a HTTPS WebSocket traffic with Mitmproxy. Currently I can read/edit WS messages with:

...
class Intercept:
    def websocket_message(self, flow):
        print(flow.messages[-1])

def start():
    return Intercept()

… as attached script to Mitmproxy.

How do I push/inject my own message to the client? Not edit existing one, but send a new message.

Hi @vitrute,

That’s a good suggestion, thanks. Implementing this is a bit tricky as the proxy connection is running outside of the mitmproxy main thread, but it’s definitely something we should think about. Would you mind lodging a feature request on GitHub for this?

Hi, @mhils,

Done - https://github.com/mitmproxy/mitmproxy/issues/2627

1 Like