You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2012/02/03 10:25:23 UTC

svn commit: r1240037 - /libcloud/trunk/libcloud/common/base.py

Author: tomaz
Date: Fri Feb  3 09:25:23 2012
New Revision: 1240037

URL: http://svn.apache.org/viewvc?rev=1240037&view=rev
Log:
Modify LoggingConnection to decompress data (if compressed), before logging it.

Modified:
    libcloud/trunk/libcloud/common/base.py

Modified: libcloud/trunk/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/base.py?rev=1240037&r1=1240036&r2=1240037&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/base.py (original)
+++ libcloud/trunk/libcloud/common/base.py Fri Feb  3 09:25:23 2012
@@ -117,6 +117,11 @@ class Response(object):
         headers = lowercase_keys(dict(response.getheaders()))
         encoding = headers.get('content-encoding', None)
 
+        original_data = getattr(response, '_original_data', None)
+
+        if original_data is not None:
+            return original_data
+
         body = response.read()
 
         if encoding in  ['zlib', 'deflate']:
@@ -238,6 +243,16 @@ class LoggingConnection():
             def makefile(self, mode, foo):
                 return StringIO(self.s)
         rr = r
+        original_data = body
+        headers = lowercase_keys(dict(r.getheaders()))
+
+        encoding = headers.get('content-encoding', None)
+
+        if encoding in  ['zlib', 'deflate']:
+            body = decompress_data('zlib', body)
+        elif encoding in ['gzip', 'x-gzip']:
+            body = decompress_data('gzip', body)
+
         if r.chunked:
             ht += "%x\r\n" % (len(body))
             ht += body
@@ -251,6 +266,8 @@ class LoggingConnection():
         rv += ht
         rv += ("\n# -------- end %d:%d response ----------\n"
                % (id(self), id(r)))
+
+        rr._original_data = body
         return (rr, rv)
 
     def _log_curl(self, method, url, body, headers):