def connection_lost(self, exc): try: log.info(self.fmt('client connection_lost')) if not self.server_protocol.transport.is_closing(): self.server_protocol.transport.close() except Exception as e: log.exception(self.fmt(e))
def eof_received(self): try: log.info(self.fmt('server eof_received')) if self.client_protocol and self.client_protocol.transport.can_write_eof( ): self.client_protocol.transport.write_eof() except Exception as e: log.exception(self.fmt(e))
def eof_received(self): try: log.info(self.fmt('client eof_received')) self.transport.close() if self.server_protocol.transport.can_write_eof(): self.server_protocol.transport.write_eof() except Exception as e: log.exception(self.fmt(e))
def connection_lost(self, exc): try: log.info(self.fmt('server connection_lost')) del connect_dict[self.peername] if self.client_protocol and not self.client_protocol.transport.is_closing( ): self.client_protocol.transport.close() except Exception as e: log.exception(self.fmt(e))
def connection_made(self, transport): try: log.info(self.fmt('client connection_made!')) self.transport = transport self.ntlm = NtlmMessageGenerator() self.try_auth_ntlm() except Exception as e: log.exception(self.fmt(e)) self.transport.close() self.server_protocol.transport.close()
def data_received(self, data): try: log.debug(self.fmt('server receive : ', data)) if not self.method: self.first_request_hand(data) if not self.client_protocol or not self.client_protocol.is_ready: self.cache += data else: log.debug(self.fmt('request write : ', data)) self.client_protocol.transport.write(data) except Exception as e: log.exception(self.fmt(e, data)) self.transport.close()
def data_received(self, data): try: log.debug(self.fmt('client receive : ', data)) if not self.is_ready: return self.hand_connect(data) if self.server_protocol.transport.is_closing(): log.info(self.fmt('server transport is closing !')) self.transport.close() return log.debug(self.fmt('response write : ', data)) self.server_protocol.transport.write(data) except Exception as e: log.exception(self.fmt(e, data)) self.server_protocol.transport.close() self.transport.close()
k, v = sys.argv[i].split("=") LISTEN_IP, LISTEN_PORT = v.split(':') LISTEN_PORT = int(LISTEN_PORT) if __name__ == "__main__": try: prase_args() loop = asyncio.ProactorEventLoop() # Each client connection will create a new protocol instance coro = loop.create_server(lambda: ProxyServerProtocol(loop), LISTEN_IP, LISTEN_PORT) server = loop.run_until_complete(coro) loop.create_task(statistic()) # Serve requests until Ctrl+C is pressed log.warning('Serving on {} , proxy {}:{}'.format( server.sockets[0].getsockname(), PROXY_IP, LISTEN_PORT)) except Exception as e: log.exception(e) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server server.close() loop.run_until_complete(server.wait_closed()) loop.close()