'Validate and \'upgrade\' the HTTP request to a WebSocket request.
If an upgrade succeeded then then handler will have `start_response`
with a status of `101`, the environ will also be updated with
`wsgi.websocket` and `wsgi.websocket_version` keys.
:param environ: The WSGI environ dict.
:param start_response: The callable used to start the response.
:param stream: File like object that will be read from/written to by
the underlying WebSocket object, if created.
:return: The WSGI response iterator is something went awry.'

def upgrade_connection(self):

    self.logger.debug('Attempting    to    upgrade    connection')
    version = self.environ.get('HTTP_SEC_WEBSOCKET_VERSION')
    if (version not in self.SUPPORTED_VERSIONS):
        msg = 'Unsupported    WebSocket    Version:    {0}'.format(version)
        self.logger.warning(msg)
        self.start_response('400    Bad    Request', [('Sec-WebSocket-Version', ',    '.join(self.SUPPORTED_VERSIONS))])
        return [msg]
    key = self.environ.get('HTTP_SEC_WEBSOCKET_KEY', '').strip()
    if (not key):
        msg = 'Sec-WebSocket-Key    header    is    missing/empty'
        self.logger.warning(msg)
        self.start_response('400    Bad    Request', [])
        return [msg]
    try:
        key_len = len(base64.b64decode(key))
    except TypeError:
        msg = 'Invalid    key:    {0}'.format(key)
        self.logger.warning(msg)
        self.start_response('400    Bad    Request', [])
        return [msg]
    if (key_len != 16):
        msg = 'Invalid    key:    {0}'.format(key)
        self.logger.warning(msg)
        self.start_response('400    Bad    Request', [])
        return [msg]
    requested_protocols = self.environ.get('HTTP_SEC_WEBSOCKET_PROTOCOL', '')
    protocol = None
    if hasattr(self.application, 'app_protocol'):
        allowed_protocol = self.application.app_protocol(self.environ['PATH_INFO'])
        if (allowed_protocol and (allowed_protocol in requested_protocols)):
            protocol = allowed_protocol
            self.logger.debug('Protocol    allowed:    {0}'.format(protocol))
    self.websocket = WebSocket(self.environ, Stream(self), self)
    self.environ.update({'wsgi.websocket_version': version, 'wsgi.websocket': self.websocket})
    if PY3:
        accept = base64.b64encode(hashlib.sha1((key + self.GUID).encode('latin-1')).digest()).decode('latin-1')
    else:
        accept = base64.b64encode(hashlib.sha1((key + self.GUID)).digest())
    headers = [('Upgrade', 'websocket'), ('Connection', 'Upgrade'), ('Sec-WebSocket-Accept', accept)]
    if protocol:
        headers.append(('Sec-WebSocket-Protocol', protocol))
    self.logger.debug('WebSocket    request    accepted,    switching    protocols')
    self.start_response('101    Switching    Protocols', headers)
