MCPcopy
hub / github.com/mitmproxy/mitmproxy / _handle_event

Method _handle_event

test/mitmproxy/proxy/test_tunnel.py:24–40  ·  view source on GitHub ↗
(self, event: Event)

Source from the content-addressed store, hash-verified

22 child_layer: layer.Layer | None = None
23
24 def _handle_event(self, event: Event) -> layer.CommandGenerator[None]:
25 if isinstance(event, Start):
26 yield Log(f"Got start. Server state: {self.context.server.state.name}")
27 elif isinstance(event, DataReceived) and event.data == b"client-hello":
28 yield SendData(self.context.client, b"client-hello-reply")
29 elif isinstance(event, DataReceived) and event.data == b"server-hello":
30 yield SendData(self.context.server, b"server-hello-reply")
31 elif isinstance(event, DataReceived) and event.data == b"open":
32 err = yield OpenConnection(self.context.server)
33 yield Log(f"Opened: {err=}. Server state: {self.context.server.state.name}")
34 elif isinstance(event, DataReceived) and event.data == b"half-close":
35 err = yield CloseTcpConnection(event.connection, half_close=True)
36 elif isinstance(event, ConnectionClosed):
37 yield Log(f"Got {event.connection.__class__.__name__.lower()} close.")
38 yield CloseConnection(event.connection)
39 else:
40 raise AssertionError
41
42
43class TTunnelLayer(tunnel.TunnelLayer):

Callers

nothing calls this directly

Calls 5

LogClass · 0.90
SendDataClass · 0.90
OpenConnectionClass · 0.90
CloseTcpConnectionClass · 0.90
CloseConnectionClass · 0.90

Tested by

no test coverage detected