Scrapy, a fast high-level web crawling & scraping framework for Python.
added COOKIES_ENABLED setting to support disabling the cookies middleware
Pablo Hoffman2fa0f75f2d3d
diff --git a/docs/topics/downloader-middleware.rst b/docs/topics/downloader-middleware.rstindex 8693c13ae..3e4c3cff7 100644--- a/docs/topics/downloader-middleware.rst+++ b/docs/topics/downloader-middleware.rst@@ -168,14 +168,26 @@ CookiesMiddleware.. class:: CookiesMiddleware- This middleware enables working with sites that need cookies. It keeps track- of merging cookies sent by servers, so that they're send in future requests- for that spider, just like a web browser would do.+ This middleware enables working with sites that require cookies, such as+ those that use sessions. It keeps track of cookies sent by web servers, and+ send them back on subsequent requests (from that spider), just like web+ browsers do.The following settings can be used to configure the cookie middleware:+* :setting:`COOKIES_ENABLED`* :setting:`COOKIES_DEBUG`+.. setting:: COOKIES_ENABLED++COOKIES_ENABLED+~~~~~~~~~~~~~~~++Default: ``True``++Whether to enable the cookies middleware. If disabled, no cookies will be sent+to web servers.+.. setting:: COOKIES_DEBUGCOOKIES_DEBUGdiff --git a/docs/topics/settings.rst b/docs/topics/settings.rstindex 10ee52e86..ce41831d8 100644--- a/docs/topics/settings.rst+++ b/docs/topics/settings.rst@@ -261,15 +261,6 @@ Default: ``8``Maximum number of spiders to scrape in parallel.-.. setting:: COOKIES_DEBUG--COOKIES_DEBUG----------------Default: ``False``--Enable debugging message of Cookies Downloader Middleware.-.. setting:: DEFAULT_ITEM_CLASSDEFAULT_ITEM_CLASSdiff --git a/scrapy/contrib/downloadermiddleware/cookies.py b/scrapy/contrib/downloadermiddleware/cookies.pyindex 1d3fbde22..d9ca178c2 100644--- a/scrapy/contrib/downloadermiddleware/cookies.py+++ b/scrapy/contrib/downloadermiddleware/cookies.py@@ -3,6 +3,7 @@ from collections import defaultdictfrom scrapy.xlib.pydispatch import dispatcherfrom scrapy import signals+from scrapy.exceptions import NotConfiguredfrom scrapy.http import Responsefrom scrapy.http.cookies import CookieJarfrom scrapy.conf import settings@@ -14,6 +15,8 @@ class CookiesMiddleware(object):debug = settings.getbool('COOKIES_DEBUG')def __init__(self):+ if not settings.getbool('COOKIES_ENABLED'):+ raise NotConfiguredself.jars = defaultdict(CookieJar)dispatcher.connect(self.spider_closed, signals.spider_closed)diff --git a/scrapy/settings/default_settings.py b/scrapy/settings/default_settings.pyindex 4bc349683..ab7b89a6a 100644--- a/scrapy/settings/default_settings.py+++ b/scrapy/settings/default_settings.py@@ -28,6 +28,7 @@ CONCURRENT_ITEMS = 100CONCURRENT_REQUESTS_PER_SPIDER = 8CONCURRENT_SPIDERS = 8+COOKIES_ENABLED = TrueCOOKIES_DEBUG = FalseDEFAULT_ITEM_CLASS = 'scrapy.item.Item'