How do I get my simple twisted proxy to work?

后端 未结 2 1182
逝去的感伤
逝去的感伤 2021-01-14 18:37

I am attempting to make use of the Twisted.Web framework.

Notice the three line comments (#line1, #line2, #line3). I want to create a proxy (gateway?) that will forw

2条回答
  •  情话喂你
    2021-01-14 19:00

    Here is the final working solution. Basically two resource request go to the GAE server, and all remaining request go to the GWT server.

    Other than implementing mhawke's change, there is only one other change, and that was adding '"/" + name' to the proxy servers path. I assume this had to be done because that portion of the path was consumed and placed in the 'name' variable.

    from twisted.internet import reactor
    from twisted.web import proxy, server
    from twisted.web.resource import Resource
    
    class Simple(Resource):
        isLeaf = False
        allowedMethods = ("GET","POST")
        def getChild(self, name, request):
            print "getChild called with name:'%s'" % name
            if name == "get.json" or name == "post.json":
                print "proxy on GAE"
                return proxy.ReverseProxyResource('localhost', 8085, "/"+name)
            else:
                print "proxy on GWT"
                return proxy.ReverseProxyResource('localhost', 8086, "/"+name)
    
    simple = Simple()
    site = server.Site(simple)
    reactor.listenTCP(8080, site)
    reactor.run()
    

    Thank you.

提交回复
热议问题