mitmproxy/examples/addons/events-websocket-specific.py

38 lines
1.3 KiB
Python
Raw Normal View History

"""WebSocket-specific events."""
2020-04-04 13:31:38 +00:00
import mitmproxy.http
import mitmproxy.websocket
class Events:
2020-11-02 20:08:54 +00:00
# WebSocket lifecycle
2020-04-04 13:31:38 +00:00
def websocket_handshake(self, flow: mitmproxy.http.HTTPFlow):
"""
Called when a client wants to establish a WebSocket connection. The
WebSocket-specific headers can be manipulated to alter the
handshake. The flow object is guaranteed to have a non-None request
attribute.
"""
def websocket_start(self, flow: mitmproxy.websocket.WebSocketFlow):
"""
2020-11-02 20:08:54 +00:00
A WebSocket connection has commenced.
2020-04-04 13:31:38 +00:00
"""
def websocket_message(self, flow: mitmproxy.websocket.WebSocketFlow):
"""
Called when a WebSocket message is received from the client or
server. The most recent message will be flow.messages[-1]. The
message is user-modifiable. Currently there are two types of
messages, corresponding to the BINARY and TEXT frame types.
"""
def websocket_error(self, flow: mitmproxy.websocket.WebSocketFlow):
"""
2020-11-02 20:08:54 +00:00
A WebSocket connection has had an error.
2020-04-04 13:31:38 +00:00
"""
def websocket_end(self, flow: mitmproxy.websocket.WebSocketFlow):
"""
2020-11-02 20:08:54 +00:00
A WebSocket connection has ended.
2020-04-04 13:31:38 +00:00
"""