protocol.py 728 B

123456789101112131415161718192021222324252627282930
  1. # coding: utf-8
  2. import logging
  3. import asyncio
  4. log = logging.getLogger('echo')
  5. class HTTPProxy(asyncio.Protocol):
  6. def __init__(self, backend):
  7. self.backend = backend
  8. self.host, self.port = backend.rsplit(':', 1)
  9. def connection_made(self, transport):
  10. log.debug('Connection made')
  11. self.transport = transport
  12. self.reader, self.writer = yield from asyncio.open_connection(
  13. self.host, self.port)
  14. log.info('connected to remote {}'.format(self.backend))
  15. def connection_lost(self, exc):
  16. log.debug('Connection lost')
  17. def data_received(self, data):
  18. log.debug('Data received')
  19. def eof_received(self):
  20. log.debug('Eof received')