httpcompression middleware improvement

This commit is contained in:
Artem Bogomyagkov 2012-10-10 12:21:59 +03:00
parent 1a905d62f5
commit 1d5967cee6
3 changed files with 7 additions and 1 deletions

View File

@ -22,3 +22,7 @@ class GzTest(unittest.TestCase):
with open(join(SAMPLEDIR, 'feed-sample1.xml'), 'rb') as f:
self.assertRaises(IOError, gunzip, f.read())
def test_gunzip_truncated_short(self):
with open(join(SAMPLEDIR, 'truncated-crc-error-short.gz'), 'rb') as f:
text = gunzip(f.read())
assert text.endswith('</html>')

View File

@ -17,7 +17,9 @@ def gunzip(data):
except (IOError, struct.error):
# complete only if there is some data, otherwise re-raise
# see issue 87 about catching struct.error
if output:
# some pages are quite small so output is '' and f.extrabuf
# contains the whole page content
if output or f.extrabuf:
output += f.extrabuf
break
else: