[Inteproxy-commits] r327 - in branches/streaming: . inteproxy

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Dec 25 18:32:10 CET 2011


Author: teichmann
Date: 2011-12-25 18:32:10 +0100 (Sun, 25 Dec 2011)
New Revision: 327

Modified:
   branches/streaming/ChangeLog
   branches/streaming/inteproxy/proxycore.py
Log:
Call new chunk/rewrite code if these conditions are met by the incoming response. Needs testing!

Modified: branches/streaming/ChangeLog
===================================================================
--- branches/streaming/ChangeLog	2011-12-23 17:56:06 UTC (rev 326)
+++ branches/streaming/ChangeLog	2011-12-25 17:32:10 UTC (rev 327)
@@ -1,3 +1,10 @@
+2011-12-25	Sascha L. Teichmann	<sascha.teichmann at intevation.de>
+
+	* inteproxy/proxycore.py: Call the new rewrite/chunking code
+	  if the incoming resonse uses transfer encoding chunked
+	  and URL rewriting is active. Otherwise the old code path
+	  is used. Needs testing!
+
 2011-12-23	Sascha L. Teichmann	<sascha.teichmann at intevation.de>
 
 	* inteproxy/proxycore.py(ransfer_chunked_rewrite): Fixed 

Modified: branches/streaming/inteproxy/proxycore.py
===================================================================
--- branches/streaming/inteproxy/proxycore.py	2011-12-23 17:56:06 UTC (rev 326)
+++ branches/streaming/inteproxy/proxycore.py	2011-12-25 17:32:10 UTC (rev 327)
@@ -105,7 +105,6 @@
             # check for fees and access constraints and run a dialog
             if self.server.show_terms_dialog:
                 handle_fees_and_access_constraints(remote_url, response)
-            self.rewrite_urls(response)
             self.handle_response(response)
 
         self.log_debug("request finished")
@@ -315,10 +314,25 @@
             self.send_header(header, value)
         self.end_headers()
 
-        transfer_encoding = response.headers.get("Transfer-encoding")
-        self.transfer_data(response.read, self.wfile.write,
-                           chunked = (transfer_encoding == "chunked"))
+        do_rewrite = self.have_to_rewrite()
+        do_chunked = response.headers.get("Transfer-encoding") == "chunked"
 
+        if do_chunked and do_rewrite:
+            self.transfer_data_rewrite_chunked(response)
+        else:
+            if do_rewrite:
+                self.rewrite_urls(response, do_rewrite)
+            self.transfer_data(response.read, self.wfile.write,
+                               chunked = do_chunked)
+
+    def transfer_data_rewrite_chunked(self, response):
+        """ TODO: Document me! """
+
+        transcoder_map = self.server.transcoder_map
+        prefix = self.server.get_inteproxy_url()
+        rewrite = transcoder_map.url_rewriter(prefix, self.log_debug)
+        self.transfer_chunked_rewrite(rewrite, response.read, self.wfile.write)
+
     def wrap_read_write_debug(read, write):
         # wrap the read/write functions if debug logging is active so
         # that the data read from the server and written to the client
@@ -416,7 +430,13 @@
         if chunked:
             write("0\r\n\r\n")
 
-    def rewrite_urls(self, response):
+    def have_to_rewrite(self):
+        """ TODO: Document me! """
+
+        return self.server.rewrite_urls and not urlparse.urlsplit(self.path)[0]
+        
+
+    def rewrite_urls(self, response, force_rewrite=False):
         """Rewrites URLs in the response if enabled in the server
 
         This method rewrites URLs in the response if the request is a
@@ -425,7 +445,7 @@
         the server.  The actual rewriting is done by the server's
         transcoder_map.
         """
-        if not urlparse.urlsplit(self.path)[0] and self.server.rewrite_urls:
+        if force_rewrite or self.have_to_rewrite():
             transcoder_map = self.server.transcoder_map
             prefix = self.server.get_inteproxy_url()
             response.body = transcoder_map.rewrite_urls(response.body, prefix,



More information about the Inteproxy-commits mailing list