Skip to content

Modify websocket messages #913

Answered by abhinavsingh
LazyCat2 asked this question in Q&A
Dec 27, 2021 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Does something like this work for you, can you double check? You should see modified websocket response in websocket responses on the client side.

class ModifyWebsocketResponsePlugin(HttpProxyBasePlugin):
    """Inspect/Modify/Send custom websocket responses."""

    def handle_upstream_chunk(self, chunk: memoryview) -> memoryview:
        remaining = chunk.tobytes()
        while len(remaining) > 0:
            response = WebsocketFrame()
            remaining = response.parse(remaining)
            self.client.queue(memoryview(
                WebsocketFrame.text(b"modified websocket response")
            ))
        return memoryview(b'')

If it works, we should check-in this plugin as …

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@abhinavsingh
Comment options

@LazyCat2
Comment options

@abhinavsingh
Comment options

@LazyCat2
Comment options

@abhinavsingh
Comment options

Answer selected by abhinavsingh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Question Questions related to proxy server
2 participants
Converted from issue

This discussion was converted from issue #911 on December 27, 2021 15:57.