mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
08895e9ba6
- restructure examples (fix #4031) - remove example dependencies from setup.py, we do not need special dependencies for our supported addons. - unify how we generate docs from code - improve example docs
22 lines
661 B
Python
22 lines
661 B
Python
"""Process individual messages from a WebSocket connection."""
|
|
import re
|
|
from mitmproxy import ctx
|
|
|
|
|
|
def websocket_message(flow):
|
|
# get the latest message
|
|
message = flow.messages[-1]
|
|
|
|
# was the message sent from the client or server?
|
|
if message.from_client:
|
|
ctx.log.info("Client sent a message: {}".format(message.content))
|
|
else:
|
|
ctx.log.info("Server sent a message: {}".format(message.content))
|
|
|
|
# manipulate the message content
|
|
message.content = re.sub(r'^Hello', 'HAPPY', message.content)
|
|
|
|
if 'FOOBAR' in message.content:
|
|
# kill the message and not send it to the other endpoint
|
|
message.kill()
|