[Inteproxy-commits] r368 - in trunk: . inteproxy test

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 26 16:54:54 CEST 2013


Author: bh
Date: 2013-06-26 16:54:54 +0200 (Wed, 26 Jun 2013)
New Revision: 368

Modified:
   trunk/ChangeLog
   trunk/inteproxy/proxycore.py
   trunk/test/test_inteproxy.py
Log:
* inteproxy/proxycore.py
(InteProxyHTTPRequestHandler.handle_proxy_request): If compression
was requested by InteProxy itself, make sure the response is
decompressed before trying to run the fees dialog. This still
leaves the case of compression requested by InteProxy's client,
but at least now it's not worse than before the compression
feature was introduced to InteProxy.

* test/test_inteproxy.py (TestInteProxyCompressedCapabilities):
New. Test case for compressed GetCapabilities response due to
InteProxy requesting compression.
(deflate): New. Helper function to compress a string as required
for the deflate Content-Encoding.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2013-06-26 13:25:43 UTC (rev 367)
+++ trunk/ChangeLog	2013-06-26 14:54:54 UTC (rev 368)
@@ -1,5 +1,21 @@
 2013-06-26  Bernhard Herzog  <bh at intevation.de>
 
+	* inteproxy/proxycore.py
+	(InteProxyHTTPRequestHandler.handle_proxy_request): If compression
+	was requested by InteProxy itself, make sure the response is
+	decompressed before trying to run the fees dialog. This still
+	leaves the case of compression requested by InteProxy's client,
+	but at least now it's not worse than before the compression
+	feature was introduced to InteProxy.
+
+	* test/test_inteproxy.py (TestInteProxyCompressedCapabilities):
+	New. Test case for compressed GetCapabilities response due to
+	InteProxy requesting compression.
+	(deflate): New. Helper function to compress a string as required
+	for the deflate Content-Encoding.
+
+2013-06-26  Bernhard Herzog  <bh at intevation.de>
+
 	* inteproxy/httpmessage.py (HTTPResponseMessage.read): Omit the
 	amount parameter entirely when calling the underlying body
 	stream's read method in the case where the caller of

Modified: trunk/inteproxy/proxycore.py
===================================================================
--- trunk/inteproxy/proxycore.py	2013-06-26 13:25:43 UTC (rev 367)
+++ trunk/inteproxy/proxycore.py	2013-06-26 14:54:54 UTC (rev 368)
@@ -107,6 +107,9 @@
             self.send_error(502)
 
         if response is not None:
+            if self.should_decompress_response:
+                response.do_decompress()
+
             # check for fees and access constraints and run a dialog
             if self.server.show_terms_dialog:
                 handle_fees_and_access_constraints(remote_url, response)

Modified: trunk/test/test_inteproxy.py
===================================================================
--- trunk/test/test_inteproxy.py	2013-06-26 13:25:43 UTC (rev 367)
+++ trunk/test/test_inteproxy.py	2013-06-26 14:54:54 UTC (rev 368)
@@ -12,6 +12,7 @@
 import httplib
 import unittest
 import base64
+import zlib
 
 import serversupport
 import support
@@ -522,6 +523,17 @@
             data = response.read()
             self.assertEquals(data, "some text")
 
+
+def deflate(s):
+    """Compress a string as requird for the deflate Content-Encoding."""
+    # This compressobj call uses undocumented parameters for the method
+    # and wbits! They are documented for Python 3, but work for 2.6 as
+    # well.
+    c = zlib.compressobj(zlib.Z_BEST_COMPRESSION, zlib.DEFLATED,
+                         -zlib.MAX_WBITS)
+    return c.compress(s) + c.flush()
+
+
 class TestInteProxyCompressedConnection(ServerTest):
     remote_contents = [
         ("/plain", [("Content-Type", "text/plain")], "not encoded"),
@@ -566,3 +578,49 @@
     #    self.assertEquals(response.status, 200)
     #    data = response.read()
     #    self.assertEquals(data, "foo")
+
+
+class TestInteProxyCompressedCapabilities(ServerTest):
+
+    capabilities = """\
+<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
+<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd">
+<WMT_MS_Capabilities updateSequence="0" version="1.1.1">
+  <Service>
+    <Title>InteProxy Compressing Test-Server</Title>
+    <Fees>0 EUR</Fees>
+    <AccessConstraints>Unrestricted</AccessConstraints>
+  </Service>
+</WMT_MS_Capabilities>
+"""
+
+    remote_contents = [
+        ("/deflate?Request=GetCapabilities",
+         [("Content-Type", "text/plain"),
+          ("Content-Encoding", "deflate")],
+         deflate(capabilities)),
+        ]
+
+    def setUp(self):
+        ServerTest.setUp(self)
+        self.old_application = inteproxy.main.the_application
+        inteproxy.main.the_application = self
+
+    def tearDown(self):
+        inteproxy.main.the_application = self.old_application
+        ServerTest.tearDown(self)
+
+    def run_fees_dialog(self, *args, **kw):
+        self.fees_parameters = args
+
+    def test_compressed_capabilities(self):
+        http = httplib.HTTPConnection("localhost", self.server.server_port)
+        http.request("GET", (self.remote_server_base_url
+                             + "deflate?Request=GetCapabilities"))
+        response = http.getresponse()
+        self.assertEquals(response.status, 200)
+        data = response.read()
+        self.assertEquals(data, self.capabilities)
+        self.assertEquals(self.fees_parameters,
+                          ('InteProxy Compressing Test-Server', '0 EUR',
+                           'Unrestricted'))



More information about the Inteproxy-commits mailing list