MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / websocket_message

Function websocket_message

examples/addons/websocket-simple.py:9–25  ·  view source on GitHub ↗
(flow: http.HTTPFlow)

Source from the content-addressed store, hash-verified

7
8
9def websocket_message(flow: http.HTTPFlow):
10 assert flow.websocket is not None # make type checker happy
11 # get the latest message
12 message = flow.websocket.messages[-1]
13
14 # was the message sent from the client or server?
15 if message.from_client:
16 logging.info(f"Client sent a message: {message.content!r}")
17 else:
18 logging.info(f"Server sent a message: {message.content!r}")
19
20 # manipulate the message content
21 message.content = re.sub(rb"^Hello", b"HAPPY", message.content)
22
23 if b"FOOBAR" in message.content:
24 # kill the message and not send it to the other endpoint
25 message.drop()

Callers

nothing calls this directly

Calls 2

infoMethod · 0.80
dropMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…