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 CONNECT. return self._requestWithEndpoint(key, self._proxyEndpoint, method, _parse(uri), headers, bodyProducer, uri)
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()) reactor.run()
if __name__ == "__main__": main()
I've tried changing the endpoint to SSL4ClientEndpoint without success.
Any help, much appreciated - G