MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / close_connection

Method close_connection

mitmproxy/proxy/server.py:439–462  ·  view source on GitHub ↗
(
        self, connection: Connection, half_close: bool = False
    )

Source from the content-addressed store, hash-verified

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
465class LiveConnectionHandler(ConnectionHandler, metaclass=abc.ABCMeta):

Callers 1

server_eventMethod · 0.95

Calls 2

logMethod · 0.95
is_closingMethod · 0.80

Tested by

no test coverage detected