chunked.py 773 B

123456789101112131415161718192021
  1. import warnings
  2. from scrapy.exceptions import ScrapyDeprecationWarning
  3. from scrapy.utils.http import decode_chunked_transfer
  4. warnings.warn("Module `scrapy.downloadermiddlewares.chunked` is deprecated, "
  5. "chunked transfers are supported by default.",
  6. ScrapyDeprecationWarning, stacklevel=2)
  7. class ChunkedTransferMiddleware(object):
  8. """This middleware adds support for chunked transfer encoding, as
  9. documented in: https://en.wikipedia.org/wiki/Chunked_transfer_encoding
  10. """
  11. def process_response(self, request, response, spider):
  12. if response.headers.get('Transfer-Encoding') == 'chunked':
  13. body = decode_chunked_transfer(response.body)
  14. return response.replace(body=body)
  15. return response