mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-28 18:58:34 +00:00
Merge pull request #359 from rocioar/master
Added COMPRESSION_ENABLED setting
This commit is contained in:
commit
c2a4046f14
@ -533,6 +533,19 @@ HttpCompressionMiddleware
|
|||||||
This middleware allows compressed (gzip, deflate) traffic to be
|
This middleware allows compressed (gzip, deflate) traffic to be
|
||||||
sent/received from web sites.
|
sent/received from web sites.
|
||||||
|
|
||||||
|
HttpCompressionMiddleware Settings
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. setting:: COMPRESSION_ENABLED
|
||||||
|
|
||||||
|
COMPRESSION_ENABLED
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Default: ``True``
|
||||||
|
|
||||||
|
Whether the Compression middleware will be enabled.
|
||||||
|
|
||||||
|
|
||||||
ChunkedTransferMiddleware
|
ChunkedTransferMiddleware
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
@ -3,12 +3,19 @@ import zlib
|
|||||||
from scrapy.utils.gz import gunzip
|
from scrapy.utils.gz import gunzip
|
||||||
from scrapy.http import Response, TextResponse
|
from scrapy.http import Response, TextResponse
|
||||||
from scrapy.responsetypes import responsetypes
|
from scrapy.responsetypes import responsetypes
|
||||||
|
from scrapy.exceptions import NotConfigured
|
||||||
|
|
||||||
|
|
||||||
class HttpCompressionMiddleware(object):
|
class HttpCompressionMiddleware(object):
|
||||||
"""This middleware allows compressed (gzip, deflate) traffic to be
|
"""This middleware allows compressed (gzip, deflate) traffic to be
|
||||||
sent/received from web sites"""
|
sent/received from web sites"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_crawler(cls, crawler):
|
||||||
|
if not crawler.settings.getbool('COMPRESSION_ENABLED'):
|
||||||
|
raise NotConfigured
|
||||||
|
return cls()
|
||||||
|
|
||||||
def process_request(self, request, spider):
|
def process_request(self, request, spider):
|
||||||
request.headers.setdefault('Accept-Encoding', 'x-gzip,gzip,deflate')
|
request.headers.setdefault('Accept-Encoding', 'x-gzip,gzip,deflate')
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ CLOSESPIDER_ERRORCOUNT = 0
|
|||||||
|
|
||||||
COMMANDS_MODULE = ''
|
COMMANDS_MODULE = ''
|
||||||
|
|
||||||
|
COMPRESSION_ENABLED = True
|
||||||
|
|
||||||
CONCURRENT_ITEMS = 100
|
CONCURRENT_ITEMS = 100
|
||||||
|
|
||||||
CONCURRENT_REQUESTS = 16
|
CONCURRENT_REQUESTS = 16
|
||||||
|
Loading…
x
Reference in New Issue
Block a user