'Attempt to connect using an HTTP Proxy.'

def _connect_proxy(self):

    address = (self.proxy_config[u'host'], int(self.proxy_config[u'port']))
    cred = None
    if self.proxy_config[u'username']:
        username = self.proxy_config[u'username']
        password = self.proxy_config[u'password']
        cred = (u'%s:%s' % (username, password))
        if (sys.version_info < (3, 0)):
            cred = bytes(cred)
        else:
            cred = bytes(cred, u'utf-8')
        cred = base64.b64encode(cred).decode(u'utf-8')
    headers = [(u'CONNECT    %s:%s    HTTP/1.0' % self.address), (u'Host:    %s:%s' % self.address), u'Proxy-Connection:    Keep-Alive', u'Pragma:    no-cache', (u'User-Agent:    SleekXMPP/%s' % sleekxmpp.__version__)]
    if cred:
        headers.append((u'Proxy-Authorization:    Basic    %s' % cred))
    headers = (u'\r\n'.join(headers) + u'\r\n\r\n')
    try:
        log.debug(u'Connecting    to    proxy:    %s:%s', *address)
        self.socket.connect(address)
        self.send_raw(headers, now=True)
        resp = u''
        while ((u'\r\n\r\n' not in resp) and (not self.stop.is_set())):
            resp += self.socket.recv(1024).decode(u'utf-8')
        log.debug(u'RECV:    %s', resp)
        lines = resp.split(u'\r\n')
        if (u'200' not in lines[0]):
            self.event(u'proxy_error', resp)
            self.event(u'connection_failed', direct=True)
            log.error(u'Proxy    Error:    %s', lines[0])
            return False
        return True
    except (Socket.error, ssl.SSLError) as serr:
        error_msg = u'Could    not    connect    to    %s:%s.    Socket    Error    #%s:    %s'
        self.event(u'socket_error', serr, direct=True)
        log.error(error_msg, self.address[0], self.address[1], serr.errno, serr.strerror)
        return False
