I recently played with HTTP proxies in twisted. After much trial and error, I think that finally something works for me. However, I want to know how, if possible, to expand this proxy server so that it can handle HTTPS pages? Here is what I got so far:
from twisted.internet import reactor from twisted.web import http from twisted.web.proxy import Proxy, ProxyRequest, ProxyClientFactory, ProxyClient class HTTPProxyClient(ProxyClient): def handleHeader(self, key, value): print "%s : %s" % (key, value) ProxyClient.handleHeader(self, key, value) def handleResponsePart(self, buffer): print buffer ProxyClient.handleResponsePart(self, buffer) class HTTPProxyFactory(ProxyClientFactory): protocol = HTTPProxyClient class HTTPProxyRequest(ProxyRequest): protocols = {'http' : HTTPProxyFactory} def process(self): print self.method for k,v in self.requestHeaders.getAllRawHeaders(): print "%s : %s" % (k,v) print "\n \n" ProxyRequest.process(self) class HTTPProxy(Proxy): requestFactory = HTTPProxyRequest factory = http.HTTPFactory() factory.protocol = HTTPProxy reactor.listenSSL(8001, factory) reactor.run()
As this code shows, for an example at the moment I am just printing everything that happens through the connection. Is it possible to handle HTTPS with the same classes? If not, how should I implement such a thing?
themaestro Jun 25 '10 at 14:01 2010-06-25 14:01
source share