This addon runs the actual proxy server.
| 111 | |
| 112 | |
| 113 | class 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, |
no outgoing calls
searching dependent graphs…