| 7 | |
| 8 | |
| 9 | def 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() |