<br>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.<br><div class="gmail_quote"><br>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 <a href="http://asdf.com.MYPROXYSITE.com" target="_blank">http://asdf.com.MYPROXYSITE.com</a> and see the contents of <a href="http://asdf.com" target="_blank">asdf.com</a>. <br>
<br>I have the following code that works well as a browser proxy, but I need to figure out how make it web based. <br><br>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? <br>
<br>Should I ditch the Proxy classes all together?<br><br>Thanks for any input.<br><br>Dave Fowler<br><br><br>from twisted.web import proxy, http<br>from twisted.python import log<br>import sys<br>log.startLogging(sys.stdout)<br>
<br>class Proxy(proxy.Proxy):<br> def __init__(self, *args):<br> print "inside Proxy"<br> proxy.Proxy.__init__(self, *args)<br> print "Proxy: ", self.__dict__<br> print dir(self)<br>
<br><br>class ProxyFactory(http.HTTPFactory): # Receive connections from the client<br> """ Receives connections from the client """<br> def __init__(self): # This function only needed for printing input and stuff<br>
print "inside proxy factory"<br> http.HTTPFactory.__init__(self) <br> print self.__dict__<br> print dir(self)<br><br> def buildProtocol(self, addr):<br> protocol = Proxy()<br>
print "making protocol for addr", addr<br> print "protocol:", protocol.__dict__<br> return protocol<br><br>if __name__ == "__main__":<br><br> PROXY_PORT = 8001<br> <br>
from twisted.internet import reactor<br> <br> reactor.listenTCP(PROXY_PORT, ProxyFactory())<br> reactor.run()<br><br><br><br><br><br>
</div><br>