Decode gzipped pages on the fly in htcache.
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 4 Dec 2013 00:04:53 +0000 (01:04 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 4 Dec 2013 00:04:53 +0000 (01:04 +0100)
manga/htcache.py

index 2f71f9a..4212db3 100644 (file)
@@ -13,6 +13,9 @@ class cache(object):
     def miss(self, url):
         s = urllib.urlopen(url)
         try:
+            if s.headers.get("content-encoding") == "gzip":
+                import gzip, StringIO
+                return gzip.GzipFile(fileobj=StringIO.StringIO(s.read()), mode="r").read()
             return s.read()
         finally:
             s.close()