[Inteproxy-commits] r353 - in branches/compression: . inteproxy test
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Feb 24 10:33:54 CET 2012
Author: aheinecke
Date: 2012-02-24 10:33:54 +0100 (Fri, 24 Feb 2012)
New Revision: 353
Modified:
branches/compression/ChangeLog
branches/compression/inteproxy/proxycore.py
branches/compression/test/test_inteproxy.py
Log:
Add exception handling to compression, return raw data
if it can not be decompressed.
Change decompressed read to allow chained read wrappers.
Add test to TestInteProxyCompressedConnection for handling
an invalid compressed response.
Improve comments.
Modified: branches/compression/ChangeLog
===================================================================
--- branches/compression/ChangeLog 2012-02-23 17:53:21 UTC (rev 352)
+++ branches/compression/ChangeLog 2012-02-24 09:33:54 UTC (rev 353)
@@ -1,5 +1,15 @@
-2012-02-22 Andre Heinecke <aheinecke at intevation.de>
+2012-02-24 Andre Heinecke <aheinecke at intevation.de>
+ * M inteproxy/proxycore.py:
+ Add exception handling to compression, return raw data
+ if it can not be decompressed.
+ Change decompressed read to allow chained read wrappers
+ * M test/test_inteproxy.py:
+ Add test to TestInteProxyCompressedConnection for handling
+ an invalid compressed response
+
+2012-02-23 Andre Heinecke <aheinecke at intevation.de>
+
* M inteproxy/httpmessage.py:
Remove compression handling but still use the read function
of HTTPMessage for reading the entire body.
@@ -9,7 +19,7 @@
algorithm and Only do decompression if the client has not
requested a compressed response or if we need to rewrite urls.
-2012-02-22 Andre Heinecke <aheinecke at intevation.de>
+2012-02-23 Andre Heinecke <aheinecke at intevation.de>
* M inteproxy/httpmessage.py:
Only decompress responses, remove the Content
Modified: branches/compression/inteproxy/proxycore.py
===================================================================
--- branches/compression/inteproxy/proxycore.py 2012-02-23 17:53:21 UTC (rev 352)
+++ branches/compression/inteproxy/proxycore.py 2012-02-24 09:33:54 UTC (rev 353)
@@ -343,14 +343,22 @@
if do_rewrite or self.do_decompress_response:
decompressor = self.get_decompress_object(response)
if decompressor:
+ # Wrap decompression around the recived data
+ orig_read = response.read
def decompressed_read(amount):
- if not response.body_has_been_read():
- return decompressor.decompress(
- HTTPResponseMessage.read(response, amount))
- else:
- return HTTPResponseMessage.read(response, amount)
+ raw_data = orig_read(amount)
+ try:
+ if not response.body_has_been_read():
+ return decompressor.decompress(raw_data)
+ else:
+ return raw_data
+ except zlib.error:
+ self.log_exception(sys.exc_info())
+ return raw_data
+ # Install the decompressor
response.read = decompressed_read
+ # Reflect the decompression in the headers
del response.headers["Content-Encoding"]
if int(response.headers.get("Content-Length", "0")):
response.read_entire_message()
Modified: branches/compression/test/test_inteproxy.py
===================================================================
--- branches/compression/test/test_inteproxy.py 2012-02-23 17:53:21 UTC (rev 352)
+++ branches/compression/test/test_inteproxy.py 2012-02-24 09:33:54 UTC (rev 353)
@@ -530,7 +530,9 @@
base64.b64decode("H4sICNwRRk8AA2Zvby50eHQAS8vP5wIAqGUyfgQAAAA=")),
("/deflate", [("Content-Type", "text/plain"),
("Content-Encoding", "deflate")],
- base64.b64decode("S8vPBwA="))]
+ base64.b64decode("S8vPBwA=")),
+ ("/invalid", [("Content-Type", "text/plain"),
+ ("Content-Encoding", "deflate")], "foo")]
def test_plain(self):
@@ -557,3 +559,10 @@
data = response.read()
self.assertEquals(data, "foo\n")
+ def test_invalid_data(self):
+ http = httplib.HTTPConnection("localhost", self.server.server_port)
+ http.request("GET", self.remote_server_base_url + "invalid")
+ response = http.getresponse()
+ self.assertEquals(response.status, 200)
+ data = response.read()
+ self.assertEquals(data, "foo")
More information about the Inteproxy-commits
mailing list