mirror of https://github.com/scrapy/scrapy.git
is_gzipped: Changed to regex to check the content-type header. Also suggested by @redapple.
This commit is contained in:
parent
346a376f5b
commit
27cbcbcdaf
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue