MCPcopy
hub / github.com/mitmproxy/mitmproxy / Proxyserver

Class Proxyserver

mitmproxy/addons/proxyserver.py:113–396  ·  view source on GitHub ↗

This addon runs the actual proxy server.

Source from the content-addressed store, hash-verified

111
112
113class Proxyserver(ServerManager):
114 """
115 This addon runs the actual proxy server.
116 """
117
118 connections: dict[tuple | str, ProxyConnectionHandler]
119 servers: Servers
120
121 is_running: bool
122 _connect_addr: Address | None = None
123
124 def __init__(self):
125 self.connections = {}
126 self.servers = Servers(self)
127 self.is_running = False
128
129 def __repr__(self):
130 return f"Proxyserver({len(self.connections)} active conns)"
131
132 @command.command("proxyserver.active_connections")
133 def active_connections(self) -> int:
134 return len(self.connections)
135
136 @contextmanager
137 def register_connection(
138 self, connection_id: tuple | str, handler: ProxyConnectionHandler
139 ):
140 self.connections[connection_id] = handler
141 try:
142 yield
143 finally:
144 del self.connections[connection_id]
145
146 def load(self, loader):
147 loader.add_option(
148 "store_streamed_bodies",
149 bool,
150 False,
151 "Store HTTP request and response bodies when streamed (see `stream_large_bodies`). "
152 "This increases memory consumption, but makes it possible to inspect streamed bodies.",
153 )
154 loader.add_option(
155 "connection_strategy",
156 str,
157 "eager",
158 "Determine when server connections should be established. When set to lazy, mitmproxy "
159 "tries to defer establishing an upstream connection as long as possible. This makes it possible to "
160 "use server replay while being offline. When set to eager, mitmproxy can detect protocols with "
161 "server-side greetings, as well as accurately mirror TLS ALPN negotiation.",
162 choices=("eager", "lazy"),
163 )
164 loader.add_option(
165 "stream_large_bodies",
166 Optional[str],
167 None,
168 """
169 Stream data to the client if request or response body exceeds the given
170 threshold. If streamed, the body will not be stored in any way,

Callers 15

test_transparentFunction · 0.90
test_wireguardFunction · 0.90
test_tun_modeFunction · 0.90
tctxFunction · 0.90
test_http_fuzz.pyFile · 0.90
test_asgi_fullFunction · 0.90
test_start_stopFunction · 0.90
test_injectFunction · 0.90
test_inject_failFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_transparentFunction · 0.72
test_wireguardFunction · 0.72
test_tun_modeFunction · 0.72
tctxFunction · 0.72
test_asgi_fullFunction · 0.72
test_start_stopFunction · 0.72
test_injectFunction · 0.72
test_inject_failFunction · 0.72
test_warn_no_nextlayerFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…