(
self, connection: Connection, half_close: bool = False
)
| 437 | self.log(f"mitmproxy has crashed!", logging.ERROR, exc_info=True) |
| 438 | |
| 439 | def close_connection( |
| 440 | self, connection: Connection, half_close: bool = False |
| 441 | ) -> None: |
| 442 | if half_close: |
| 443 | if not connection.state & ConnectionState.CAN_WRITE: |
| 444 | return |
| 445 | self.log(f"half-closing {connection}", logging.DEBUG) |
| 446 | try: |
| 447 | writer = self.transports[connection].writer |
| 448 | assert writer |
| 449 | if not writer.is_closing(): |
| 450 | writer.write_eof() |
| 451 | except OSError: |
| 452 | # if we can't write to the socket anymore we presume it completely dead. |
| 453 | connection.state = ConnectionState.CLOSED |
| 454 | else: |
| 455 | connection.state &= ~ConnectionState.CAN_WRITE |
| 456 | else: |
| 457 | connection.state = ConnectionState.CLOSED |
| 458 | |
| 459 | if connection.state is ConnectionState.CLOSED: |
| 460 | handler = self.transports[connection].handler |
| 461 | assert handler |
| 462 | handler.cancel("closed by command") |
| 463 | |
| 464 | |
| 465 | class LiveConnectionHandler(ConnectionHandler, metaclass=abc.ABCMeta): |
no test coverage detected