'Negotiates a connection through an HTTP server.
NOTE: This currently only supports HTTP CONNECT-style proxies.'

def _negotiate_HTTP(self, dest_addr, dest_port):

    (proxy_type, addr, port, rdns, username, password) = self.proxy
    addr = (dest_addr if rdns else socket.gethostbyname(dest_addr))
    self.sendall(((((((('CONNECT    ' + addr.encode('idna')) + ':') + str(dest_port).encode()) + '    HTTP/1.1\r\n') + 'Host:    ') + dest_addr.encode('idna')) + '\r\n\r\n'))
    fobj = self.makefile()
    status_line = fobj.readline()
    fobj.close()
    if (not status_line):
        raise GeneralProxyError('Connection    closed    unexpectedly')
    try:
        (proto, status_code, status_msg) = status_line.split('    ', 2)
    except ValueError:
        raise GeneralProxyError('HTTP    proxy    server    sent    invalid    response')
    if (not proto.startswith('HTTP/')):
        raise GeneralProxyError('Proxy    server    does    not    appear    to    be    an    HTTP    proxy')
    try:
        status_code = int(status_code)
    except ValueError:
        raise HTTPError('HTTP    proxy    server    did    not    return    a    valid    HTTP    status')
    if (status_code != 200):
        error = '{0}:    {1}'.format(status_code, status_msg)
        if (status_code in (400, 403, 405)):
            error += '\n[*]    Note:    The    HTTP    proxy    server    may    not    be    supported    by    PySocks    (must    be    a    CONNECT    tunnel    proxy)'
        raise HTTPError(error)
    self.proxy_sockname = ('0.0.0.0', 0)
    self.proxy_peername = (addr, dest_port)
