is_gzipped: Changed to regex to check the content-type header. Also suggested by @redapple.

This commit is contained in:
Joakim Uddholm 2016-06-14 14:39:16 +02:00 committed by Paul Tremberth
parent 346a376f5b
commit 27cbcbcdaf
1 changed files with 3 additions and 2 deletions

View File

@ -7,7 +7,7 @@ except ImportError:
from gzip import GzipFile
import six
import re
# - Python>=3.5 GzipFile's read() has issues returning leftover
# uncompressed data when input is corrupted
@ -50,8 +50,9 @@ def gunzip(data):
raise
return output
_is_gzipped_re = re.compile(br'^application/(x-)?gzip\b', re.I)
def is_gzipped(response):
"""Return True if the response is gzipped, or False otherwise"""
ctype = response.headers.get('Content-Type', b'')
return b'application/x-gzip' in ctype or b'application/gzip' in ctype
return not _is_gzipped_re.search(ctype) is None