Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

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

Joakim Uddholm259426ec9995
diff --git a/scrapy/utils/gz.py b/scrapy/utils/gz.py
index f174950a4..f2a9555b1 100644
--- a/scrapy/utils/gz.py
+++ b/scrapy/utils/gz.py
@@ -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