'Upgrade the HTTP connection to a WebSocket and verify.'

def _upgrade(self, url):

    reqdata = 'GET    /websockify    HTTP/1.1\r\n'
    reqdata += ('Host:    %s:%s\r\n' % (url.hostname, url.port))
    reqdata += 'Upgrade:    websocket\r\nConnection:    Upgrade\r\n'
    reqdata += ('Cookie:    %s\r\n' % url.query)
    reqdata += 'Sec-WebSocket-Key:    x3JJHMbDL1EzLkh9GBhXDw==\r\n'
    reqdata += 'Sec-WebSocket-Version:    13\r\n'
    reqdata += 'Sec-WebSocket-Protocol:    binary\r\n\r\n'
    self._socket.sendall(reqdata.encode('utf8'))
    self.response = data = self._socket.recv(4096)
    end_loc = self.response.find('\r\n\r\n')
    while (data and (end_loc < 0)):
        data = self._socket.recv(4096)
        self.response += data
        end_loc = self.response.find('\r\n\r\n')
    if (len(self.response) > (end_loc + 4)):
        self.cached_stream = self.response[(end_loc + 4):]
        self.response = self.response[:(end_loc + 4)]
