Ok, I've read the entire Twisted O'Reilly book and gone through many of the docs and tutorials but I still need a bit of direction.

I'm trying to make a simple web-based proxy.  Similar to the proxy in the Twisted book, but with a web interface.  So I could go to   http://asdf.com.MYPROXYSITE.com and see the contents of asdf.com

I have the following code that works well as a browser proxy, but I need to figure out how make it web based. 

My thoughts are that I need to make an HTTP server and then adjust the address in the protocol before finishing the proxy request.  Am I on the right track?  Does anyone have examples of this?

Should I ditch the Proxy classes all together?

Thanks for any input.

Dave Fowler


from twisted.web import proxy, http
from twisted.python import log
import sys
log.startLogging(sys.stdout)

class Proxy(proxy.Proxy):
    def __init__(self, *args):
        print "inside Proxy"
        proxy.Proxy.__init__(self, *args)
        print "Proxy: ", self.__dict__
        print dir(self)
   

class ProxyFactory(http.HTTPFactory):  # Receive connections from the client
    """ Receives connections from the client """
    def __init__(self):  # This function only needed for printing input and stuff
        print "inside proxy factory"
        http.HTTPFactory.__init__(self) 
        print self.__dict__
        print dir(self)

    def buildProtocol(self, addr):
        protocol = Proxy()
        print "making protocol for addr", addr
        print "protocol:", protocol.__dict__
        return protocol

if __name__ == "__main__":

    PROXY_PORT = 8001
   
    from twisted.internet import reactor
   
    reactor.listenTCP(PROXY_PORT, ProxyFactory())
    reactor.run()