Skip to content

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.rst
index 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_DEBUG
COOKIES_DEBUG
diff --git a/docs/topics/settings.rst b/docs/topics/settings.rst
index 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_CLASS
DEFAULT_ITEM_CLASS
diff --git a/scrapy/contrib/downloadermiddleware/cookies.py b/scrapy/contrib/downloadermiddleware/cookies.py
index 1d3fbde22..d9ca178c2 100644
--- a/scrapy/contrib/downloadermiddleware/cookies.py
+++ b/scrapy/contrib/downloadermiddleware/cookies.py
@@ -3,6 +3,7 @@ from collections import defaultdict
from scrapy.xlib.pydispatch import dispatcher
from scrapy import signals
+from scrapy.exceptions import NotConfigured
from scrapy.http import Response
from scrapy.http.cookies import CookieJar
from 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 NotConfigured
self.jars = defaultdict(CookieJar)
dispatcher.connect(self.spider_closed, signals.spider_closed)
diff --git a/scrapy/settings/default_settings.py b/scrapy/settings/default_settings.py
index 4bc349683..ab7b89a6a 100644
--- a/scrapy/settings/default_settings.py
+++ b/scrapy/settings/default_settings.py
@@ -28,6 +28,7 @@ CONCURRENT_ITEMS = 100
CONCURRENT_REQUESTS_PER_SPIDER = 8
CONCURRENT_SPIDERS = 8
+COOKIES_ENABLED = True
COOKIES_DEBUG = False
DEFAULT_ITEM_CLASS = 'scrapy.item.Item'