[Twisted-Python] Problems in twisted.web.proxy.ReverseProxyResource

Allen Chan user143 at tsolver.com
Wed Jan 1 20:47:01 EST 2003


(1) The part of the URI starting with a '?' is not passed along to the
reverse proxy server.
(2) The browser hangs if conditional GET requests passed along to the
reverse proxy server returns a 304 (Not Modified) result.

The following diffs in twisted/web/proxy.py patches ReverseProxyResource to
temporarily get around these two problems.  However, more experienced
twisted developers may find better solutions.

--- proxy.py	Sun Dec 15 10:59:04 2002
+++ c:proxy.py	Thu Jan 02 01:27:43 2003
@@ -177,9 +177,22 @@

     def render(self, request):
         request.received_headers['host'] = self.host
-        clientFactory = ProxyClientFactory(request.method, self.path,
-                                     request.clientproto,
-                                     request.getAllHeaders(),
+
+        # need to add back the part of the uri starting with the '?'
+        newuri = self.path
+        if len(request.path) < len(request.uri):
+            newuri += request.uri[len(request.path):]
+
+        # need to remove all conditional get headers since the 304 response
+        # is not supported
+        newheaders = {}
+        for (k,v) in request.getAllHeaders().items():
+            if k[:3] != "if-":
+                newheaders[k] = v
+
+        clientFactory = ProxyClientFactory(request.method, newuri,
+                                     request.clientproto,
+                                     newheaders,
                                      request.content.read(),
                                      request)
         reactor.connectTCP(self.host, self.port, clientFactory)





More information about the Twisted-Python mailing list