Scrapy, a fast high-level web crawling & scraping framework for Python.
requests with no-cache set must force revalidation of cached responses
Daniel Graña3f03a2ca509b
diff --git a/scrapy/contrib/downloadermiddleware/httpcache.py b/scrapy/contrib/downloadermiddleware/httpcache.pyindex aa736708b..b3ac193b4 100644--- a/scrapy/contrib/downloadermiddleware/httpcache.py+++ b/scrapy/contrib/downloadermiddleware/httpcache.py@@ -79,7 +79,8 @@ class RFC2616Policy(object):def is_cached_response_fresh(self, cachedresponse, request):cc = self._parse_cachecontrol(cachedresponse)- if 'no-cache' in cc:+ ccreq = self._parse_cachecontrol(request)+ if 'no-cache' in cc or 'no-cache' in ccreq:return Falsenow = time()diff --git a/scrapy/tests/test_downloadermiddleware_httpcache.py b/scrapy/tests/test_downloadermiddleware_httpcache.pyindex 28b3026f0..00baf4748 100644--- a/scrapy/tests/test_downloadermiddleware_httpcache.py+++ b/scrapy/tests/test_downloadermiddleware_httpcache.py@@ -241,15 +241,27 @@ class RFC2616MiddlewareTest(DefaultStorageTest):headers={'Expires': self.tomorrow})req0 = Request('http://example.com')req1 = req0.replace(headers={'Cache-Control': 'no-store'})+ req2 = req0.replace(headers={'Cache-Control': 'no-cache'})with self._middleware() as mw:+ # response for a request with no-store must not be cachedres1 = self._process_requestresponse(mw, req1, res0)self.assertEqualResponse(res1, res0)assert mw.storage.retrieve_response(self.spider, req1) is None+ # Re-do request without no-store and expect it to be cachedres2 = self._process_requestresponse(mw, req0, res0)assert 'cached' not in res2.flagsres3 = mw.process_request(req0, self.spider)assert 'cached' in res3.flagsself.assertEqualResponse(res2, res3)+ # request with no-cache directive must not return cached response+ # but it allows new response to be stored+ res0b = res0.replace(body='foo')+ res4 = self._process_requestresponse(mw, req2, res0b)+ self.assertEqualResponse(res4, res0b)+ assert 'cached' not in res4.flags+ res5 = self._process_requestresponse(mw, req0, None)+ self.assertEqualResponse(res5, res0b)+ assert 'cached' in res5.flagsdef test_response_cacheability(self):responses = [