[Twisted-web] web proxy with twistd

Andreas De Stefani andreas.destefani at ucd.ie
Wed Jul 20 10:08:23 MDT 2005

Hello twisted programmers!

i was trying to write a proxy which allows me to access twisted and 
nevow websites on a local development server infrastructure to which i 
dont have direct access (the proxy sits on the gateway).

It works fine if i access external websites but it fails for homebrewed 
twisted websites and i always get a
No Such Resource File not found Error (the websites are running on port 
8080, 8081 ... but don't think thats the reason?! )

I might do somethin wrong in my proxy i suppose, here is my code


from twisted.internet import protocol
from twisted.internet import reactor
from twisted.protocols import http
from twisted.web import proxy, server, resource

class ReverseProxyResource(resource.Resource):

        def getChild(self, path, request):
                return self

        def render(self, request):
                d = request.received_headers.get('destination')
                hp = request.received_headers['host']
                if ':' in hp:
                        host, port = hp.split(':')
                        port = int(port)
                        host = hp
                        port = 80

                print 'forwarding to: ' + host + ' port ' + str(port)
                clientFactory = proxy.ProxyClientFactory(request.method, 
                reactor.connectTCP(host, port, clientFactory)
                return server.NOT_DONE_YET

site = server.Site(ReverseProxyResource())
reactor.listenTCP(8484, site)

Thanks for your help!


More information about the Twisted-web mailing list