Skip to content

Commit

Permalink
Place encodings in response's flags issue scrapy#1988
Browse files Browse the repository at this point in the history
  • Loading branch information
VorBoto committed Sep 18, 2019
1 parent 25d4760 commit ccbb524
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions scrapy/downloadermiddlewares/httpcompression.py
Expand Up @@ -48,17 +48,11 @@ def process_response(self, request, response, spider):
# force recalculating the encoding until we make sure the
# responsetypes guessing is reliable
kwargs['encoding'] = None

if self.keep_encoding_header:
#check encoding of outgoing response
#dont know if i can do this with a RespinceTypes object
out_encoding = TextResponse(respcls)._body_inferred_encoding()
kwargs['flags'] = out_encoding

kwargs['flags'] = [encoding]
response = response.replace(**kwargs)
if not self.keep_encoding_header:
if not content_encoding:
del response.headers['Content-Encoding']
if not content_encoding:
del response.headers['Content-Encoding']
return response

def _decode(self, body, encoding):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_downloadermiddleware_httpcompression.py
Expand Up @@ -28,7 +28,7 @@ class HttpCompressionTest(TestCase):

def setUp(self):
#need to find way to access settings here
crawler = get_crawler(Spider,{'HTTPCOMPRESSION_HEADERS_KEEP':False,
crawler = get_crawler(Spider,{'HTTPCOMPRESSION_HEADERS_KEEP':True,
'COMPRESSION_ENABLED':True})
self.spider = crawler._create_spider('foo')
self.mw = HttpCompressionMiddleware.from_crawler(crawler)
Expand Down

0 comments on commit ccbb524

Please sign in to comment.