aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simple/websocket_messages.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2020-04-04 15:54:00 +0200
committerGitHub <noreply@github.com>2020-04-04 15:54:00 +0200
commitac83db3b840ecdbbc8ba232ae151b75d15e4a679 (patch)
tree697a56dd92027027a3b30657ccaabee6dbd011c5 /examples/simple/websocket_messages.py
parent9cc5d933c19b968df4d58fde6f69e829d3e064b9 (diff)
parent678be7a052007e26939b5f0cfa13200ab032cf86 (diff)
downloadmitmproxy-ac83db3b840ecdbbc8ba232ae151b75d15e4a679.tar.gz
mitmproxy-ac83db3b840ecdbbc8ba232ae151b75d15e4a679.tar.bz2
mitmproxy-ac83db3b840ecdbbc8ba232ae151b75d15e4a679.zip
Merge pull request #3898 from Kriechi/websocket-docs
improve scripting docs
Diffstat (limited to 'examples/simple/websocket_messages.py')
-rw-r--r--examples/simple/websocket_messages.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/examples/simple/websocket_messages.py b/examples/simple/websocket_messages.py
index 719e7b10..071ea21f 100644
--- a/examples/simple/websocket_messages.py
+++ b/examples/simple/websocket_messages.py
@@ -6,8 +6,15 @@ def websocket_message(flow):
# get the latest message
message = flow.messages[-1]
- # simply print the content of the message
- ctx.log.info(message.content)
+ # 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()