Skip to content

Commit

Permalink
Add HEADERS_KEEP variable to settings and to HttpCompressionMiddlewar…
Browse files Browse the repository at this point in the history
…e class (scrapy#1988)
  • Loading branch information
cwen13 committed Sep 14, 2019
1 parent 534de73 commit 5f068dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions scrapy/downloadermiddlewares/httpcompression.py
Expand Up @@ -18,6 +18,10 @@
class HttpCompressionMiddleware(object):
"""This middleware allows compressed (gzip, deflate) traffic to be
sent/received from web sites"""

HEADERS_KEEP = setting.getbool('HEADERS_KEEP')


@classmethod
def from_crawler(cls, crawler):
if not crawler.settings.getbool('COMPRESSION_ENABLED'):
Expand Down Expand Up @@ -45,8 +49,9 @@ def process_response(self, request, response, spider):
# responsetypes guessing is reliable
kwargs['encoding'] = None
response = response.replace(**kwargs)
if not content_encoding:
del response.headers['Content-Encoding']
if not HEADERS_KEEP:
if not content_encoding:
del response.headers['Content-Encoding']

return response

Expand Down
2 changes: 2 additions & 0 deletions scrapy/settings/default_settings.py
Expand Up @@ -170,6 +170,8 @@
FTP_PASSWORD = 'guest'
FTP_PASSIVE_MODE = True

HEADERS_KEEP = False

HTTPCACHE_ENABLED = False
HTTPCACHE_DIR = 'httpcache'
HTTPCACHE_IGNORE_MISSING = False
Expand Down

0 comments on commit 5f068dc

Please sign in to comment.