A connection between a client and mitmproxy.
| 173 | |
| 174 | @dataclass(eq=False, repr=False, kw_only=True) |
| 175 | class Client(Connection): # type: ignore[override] |
| 176 | """A connection between a client and mitmproxy.""" |
| 177 | |
| 178 | peername: Address |
| 179 | """The client's address.""" |
| 180 | sockname: Address |
| 181 | """The local address we received this connection on.""" |
| 182 | |
| 183 | mitmcert: certs.Cert | None = None |
| 184 | """ |
| 185 | The certificate used by mitmproxy to establish TLS with the client. |
| 186 | """ |
| 187 | |
| 188 | proxy_mode: mode_specs.ProxyMode = field( |
| 189 | default=mode_specs.ProxyMode.parse("regular") |
| 190 | ) |
| 191 | """The proxy server type this client has been connecting to.""" |
| 192 | |
| 193 | timestamp_start: float = field(default_factory=time.time) |
| 194 | """*Timestamp:* TCP SYN received""" |
| 195 | |
| 196 | def __str__(self): |
| 197 | if self.alpn: |
| 198 | tls_state = f", alpn={self.alpn.decode(errors='replace')}" |
| 199 | elif self.tls_established: |
| 200 | tls_state = ", tls" |
| 201 | else: |
| 202 | tls_state = "" |
| 203 | state = self.state.name |
| 204 | assert state |
| 205 | return f"Client({human.format_address(self.peername)}, state={state.lower()}{tls_state})" |
| 206 | |
| 207 | @property |
| 208 | def address(self): # pragma: no cover |
| 209 | """*Deprecated:* An outdated alias for Client.peername.""" |
| 210 | warnings.warn( |
| 211 | "Client.address is deprecated, use Client.peername instead.", |
| 212 | DeprecationWarning, |
| 213 | stacklevel=2, |
| 214 | ) |
| 215 | return self.peername |
| 216 | |
| 217 | @address.setter |
| 218 | def address(self, x): # pragma: no cover |
| 219 | warnings.warn( |
| 220 | "Client.address is deprecated, use Client.peername instead.", |
| 221 | DeprecationWarning, |
| 222 | stacklevel=2, |
| 223 | ) |
| 224 | self.peername = x |
| 225 | |
| 226 | @property |
| 227 | def cipher_name(self) -> str | None: # pragma: no cover |
| 228 | """*Deprecated:* An outdated alias for Connection.cipher.""" |
| 229 | warnings.warn( |
| 230 | "Client.cipher_name is deprecated, use Client.cipher instead.", |
| 231 | DeprecationWarning, |
| 232 | stacklevel=2, |
searching dependent graphs…