2020-06-22 23:53:39 +00:00
|
|
|
"""Process individual messages from a WebSocket connection."""
|
2018-10-09 16:24:18 +00:00
|
|
|
import re
|
|
|
|
from mitmproxy import ctx
|
|
|
|
|
|
|
|
|
|
|
|
def websocket_message(flow):
|
|
|
|
# get the latest message
|
|
|
|
message = flow.messages[-1]
|
|
|
|
|
2020-04-04 13:31:38 +00:00
|
|
|
# was the message sent from the client or server?
|
|
|
|
if message.from_client:
|
2020-11-20 18:25:26 +00:00
|
|
|
ctx.log.info(f"Client sent a message: {message.content}")
|
2020-04-04 13:31:38 +00:00
|
|
|
else:
|
2020-11-20 18:25:26 +00:00
|
|
|
ctx.log.info(f"Server sent a message: {message.content}")
|
2018-10-09 16:24:18 +00:00
|
|
|
|
|
|
|
# manipulate the message content
|
|
|
|
message.content = re.sub(r'^Hello', 'HAPPY', message.content)
|
2020-04-04 13:31:38 +00:00
|
|
|
|
|
|
|
if 'FOOBAR' in message.content:
|
|
|
|
# kill the message and not send it to the other endpoint
|
2020-12-28 16:35:23 +00:00
|
|
|
message.content = ""
|