From 7156dd55225a27fd2e31b7d2f8e6e57b779f3021 Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 24 Nov 2013 21:55:07 +0100 Subject: [PATCH] Support for non-textual gzipped http content --- morss.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/morss.py b/morss.py index fe72906..0234922 100644 --- a/morss.py +++ b/morss.py @@ -233,15 +233,15 @@ class SimpleDownload(urllib2.HTTPCookieProcessor): def http_response(self, req, resp): urllib2.HTTPCookieProcessor.http_response(self, req, resp) + odata = data = resp.read() - if 200 <= resp.code < 300 and resp.info().maintype == 'text': - data = resp.read() - + if 200 <= resp.code < 300: # gzip if resp.headers.get('Content-Encoding') == 'gzip': log('un-gzip') data = GzipFile(fileobj=StringIO(data), mode='r').read() + if 200 <= resp.code < 300 and resp.info().maintype == 'text': # redirect if resp.info().type in MIMETYPE['html']: match = re.search(r'(?i)]*?url=(http.*?)["\']', data) @@ -262,6 +262,7 @@ class SimpleDownload(urllib2.HTTPCookieProcessor): if self.decode: data = decodeHTML(data, resp) + if odata != data: fp = StringIO(data) old_resp = resp resp = urllib2.addinfourl(fp, old_resp.headers, old_resp.url, old_resp.code)