Skip to content

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

Make HttpCompressionMiddleware changes backward-comaptible

Adrián Chaves5f2827efe7b0
diff --git a/scrapy/downloadermiddlewares/httpcompression.py b/scrapy/downloadermiddlewares/httpcompression.py
index f03294d65..1a3f6962a 100644
--- a/scrapy/downloadermiddlewares/httpcompression.py
+++ b/scrapy/downloadermiddlewares/httpcompression.py
@@ -37,8 +37,10 @@ class HttpCompressionMiddleware:
"""This middleware allows compressed (gzip, deflate) traffic to be
sent/received from web sites"""
- def __init__(self, *, crawler=None):
+ def __init__(self, stats=None, *, crawler=None):
if not crawler:
+ if stats:
+ self.stats = stats
return
self.stats = crawler.stats
self._max_size = crawler.settings.getint("DOWNLOAD_MAXSIZE")