code: def on_headers(self, response, exc=None):
          '''Websocket upgrade as ``on_headers`` event.'''
  
          if response.status_code == 101:
              connection = response.connection
              request = response.request
              handler = request.websocket_handler
              if not handler:
                  handler = WS()
              parser = request.client.frame_parser(kind=1)
              consumer = partial(WebSocketClient.create,
                                 response, handler, parser)
              connection.upgrade(consumer)
              response.event('post_request').fire()
              websocket = connection.current_consumer()
              response.request_again = lambda r: websockef on_headers(self, response, exc=None):
          '''Websocket upgrade as ``on_headers`` event.'''
  
          if response.status_code == 101:
              connection = response.connection
              request = response.request
              handler = request.websocket_handler
              if not handler:
                  handler = WS()
              parser = request.client.frame_parser(kind=1)
              consumer = partial(WebSocketClient.create,
                                 response, handler, parser)
              connection.upgrade(consumer)
              response.event('post_request').fire()
              websocket = connection.current_consumer()
              response.request_again = lambda r: websocket
docs: Websocket upgrade as ``on_headers`` event.