Add error handling for zlib decompression errors when decompressing javascript from proxy

This commit is contained in:
englehardt 2015-09-16 01:22:27 +00:00
Родитель 8240733da6
Коммит 9c2473e133
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -82,9 +82,17 @@ def save_javascript_content(logger, browser_params, manager_params, msg):
# Firefox currently only accepts gzip/deflate
script = ''
if 'gzip' in msg.response.headers['Content-Encoding']:
script = zlib.decompress(msg.response.content, zlib.MAX_WBITS|16)
try:
script = zlib.decompress(msg.response.content, zlib.MAX_WBITS|16)
except zlib.error as e:
logger.error('Received zlib error when trying to decompress gzipped javascript: %s' % str(e))
return
elif 'deflate' in msg.response.headers['Content-Encoding']:
script = zlib.decompress(msg.response.content, -zlib.MAX_WBITS)
try:
script = zlib.decompress(msg.response.content, -zlib.MAX_WBITS)
except zlib.error as e:
logger.error('Received zlib error when trying to decompress deflated javascript: %s' % str(e))
return
elif msg.response.headers['Content-Encoding'] == []:
script = msg.response.content
else: