[Twisted-web] Does twisted-web 12.01 support proxing HTTPS with ProxyAgent ?

Geoff Metselaar geoff.metselaar at gmail.com
Thu Dec 13 12:16:55 EST 2012


The code suggests it does - but I can't get it to work.

class ProxyAgent(_AgentBase):
    An HTTP agent able to cross HTTP proxies.

    @ivar _proxyEndpoint: The endpoint used to connect to the proxy.

    @since: 11.1

    def __init__(self, endpoint, reactor=None, pool=None):
        if reactor is None:
            from twisted.internet import reactor
        _AgentBase.__init__(self, reactor, pool)
        self._proxyEndpoint = endpoint

    def request(self, method, uri, headers=None, bodyProducer=None):
        Issue a new request via the configured proxy.
        # Cache *all* connections under the same key, since we are only
        # connecting to a single destination, the proxy:
        key = ("http-proxy", self._proxyEndpoint)

        # To support proxying HTTPS via CONNECT, we will use key
        # ("http-proxy-CONNECT", scheme, host, port), and an endpoint that
        # wraps _proxyEndpoint with an additional callback to do the
        return self._requestWithEndpoint(key, self._proxyEndpoint, method,
                                         _parse(uri), headers, bodyProducer,

The "Using a http proxy" -
http://twistedmatrix.com/documents/current/web/howto/client.html  works,
provided the target url is http ( not https as shown in the example ).
I'm attempting to adapt this example to confirm https proxing is possible

from twisted.python.log import err
from twisted.web.client import ProxyAgent
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ClientEndpoint

def display(response):
    print "Received response"
    print response

def main():
    endpoint = TCP4ClientEndpoint(reactor, "localhost", 8000)
    agent = ProxyAgent(endpoint)
    d = agent.request("GET", "https://example.com/")
    d.addCallbacks(display, err)
    d.addCallback(lambda ignored: reactor.stop())

if __name__ == "__main__":

I've tried changing the endpoint to SSL4ClientEndpoint without success.

Any help, much appreciated
- G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20121213/6e6ed40e/attachment.htm 

More information about the Twisted-web mailing list