MCPcopy
hub / github.com/mitmproxy/mitmproxy / __init__

Method __init__

mitmproxy/addons/clientplayback.py:88–110  ·  view source on GitHub ↗
(self, flow: http.HTTPFlow, options: Options)

Source from the content-addressed store, hash-verified

86 layer: layers.HttpLayer
87
88 def __init__(self, flow: http.HTTPFlow, options: Options) -> None:
89 client = flow.client_conn.copy()
90 client.state = ConnectionState.OPEN
91
92 context = Context(client, options)
93 context.server = Server(address=(flow.request.host, flow.request.port))
94 if flow.request.scheme == "https":
95 context.server.tls = True
96 context.server.sni = flow.request.pretty_host
97 if options.mode and options.mode[0].startswith("upstream:"):
98 mode = UpstreamMode.parse(options.mode[0])
99 assert isinstance(mode, UpstreamMode) # remove once mypy supports Self.
100 context.server.via = flow.server_conn.via = (mode.scheme, mode.address)
101
102 super().__init__(context)
103
104 if options.mode and options.mode[0].startswith("upstream:"):
105 self.layer = layers.HttpLayer(context, HTTPMode.upstream)
106 else:
107 self.layer = layers.HttpLayer(context, HTTPMode.transparent)
108 self.layer.connections[client] = MockServer(flow, context.fork())
109 self.flow = flow
110 self.done = asyncio.Event()
111
112 async def replay(self) -> None:
113 await self.server_event(events.Start())

Callers

nothing calls this directly

Calls 7

forkMethod · 0.95
ContextClass · 0.90
ServerClass · 0.90
MockServerClass · 0.85
copyMethod · 0.45
parseMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected