code: def pre_request(self, response, exc=None):
          
          if response.request.method == 'CONNECT':
              self.start_response(
                  '200 Connection established',
                  [('content-length', '0')]
              )
              # send empty byte so that headers are sent
              self.future.set_result([b''])
              # proxy - server connection
              upstream = response.connection
              # client - proxy connection
              dostream = self.connection
              # Upgrade downstream connection
              dostream.upgrade(partial(StreamTunnel.create, upstream))
              #
              # upstream upgrade
              upstream.upgrade(partial(StreamTunnel.create, dostream))
              response.fire_event('post_request')
              # abort the event
              raise AbortEvent
          else:
              response.event('data_processed').bind(self.data_processed)
              response.event('post_request').bind(self.post_request)
docs: Start the tunnel.
  
          This is a callback fired once a connection with upstream server is
          established.