Ticket #4704: Agent.proxy.support.patch

File Agent.proxy.support.patch, 1.8 KB (added by wirepair, 3 years ago)

Agent proxy support patch

  • twisted/web/client.py

     
    617617    """ 
    618618    L{Agent} is a very basic HTTP client.  It supports I{HTTP} and I{HTTPS} 
    619619    scheme URIs (but performs no certificate checking by default).  It does not 
    620     support persistent connections. 
     620    support persistent connections. It does support a HTTP proxy. 
    621621 
    622622    @ivar _reactor: The L{IReactorTCP} and L{IReactorSSL} implementation which 
    623623        will be used to set up connections over which to issue requests. 
    624624 
    625625    @ivar _contextFactory: A web context factory which will be used to create 
    626626        SSL context objects for any SSL connections the agent needs to make. 
    627  
     627     
     628    @ivar _proxy: A tuple of a C{str} hostname and a C{int} of the port of an 
     629        HTTP proxy.  
    628630    @since: 9.0 
    629631    """ 
    630632    _protocol = HTTP11ClientProtocol 
    631633 
    632     def __init__(self, reactor, contextFactory=WebClientContextFactory()): 
     634    def __init__(self, reactor, contextFactory=WebClientContextFactory(), 
     635                 proxy=None): 
    633636        self._reactor = reactor 
    634637        self._contextFactory = contextFactory 
     638        self._proxy = proxy 
    635639 
    636640 
    637641    def _wrapContextFactory(self, host, port): 
     
    704708        @rtype: L{Deferred} 
    705709        """ 
    706710        scheme, host, port, path = _parse(uri) 
    707         d = self._connect(scheme, host, port) 
     711        d = None 
     712        if self._proxy is None or scheme == 'https': 
     713            d = self._connect(scheme, host, port) 
     714        else: 
     715            d = self._connect(scheme, self._proxy[0], self._proxy[1]) 
     716            path = uri 
     717           
    708718        if headers is None: 
    709719            headers = Headers() 
    710720        if not headers.hasHeader('host'):