From 678be7a052007e26939b5f0cfa13200ab032cf86 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 4 Apr 2020 15:31:38 +0200 Subject: improve scripting docs --- examples/simple/websocket_messages.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'examples/simple/websocket_messages.py') 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() -- cgit v1.2.3