From: Ricardo N. <svn...@pl...> - 2010-03-08 06:19:20
|
Author: newbery Date: Mon Mar 8 06:19:11 2010 New Revision: 34634 Modified: plone.app.caching/trunk/plone/app/caching/operations/default.py plone.app.caching/trunk/plone/app/caching/operations/utils.py plone.app.caching/trunk/plone/app/caching/tests/test_operation_utils.py plone.app.caching/trunk/plone/app/caching/tests/test_profile_with_caching_proxy.py plone.app.caching/trunk/plone/app/caching/tests/test_profile_without_caching_proxy.py Log: Fixing the RR 304s Modified: plone.app.caching/trunk/plone/app/caching/operations/default.py ============================================================================== --- plone.app.caching/trunk/plone/app/caching/operations/default.py (original) +++ plone.app.caching/trunk/plone/app/caching/operations/default.py Mon Mar 8 06:19:11 2010 @@ -227,7 +227,7 @@ adapts(ICookedFile, IHTTPRequest) def interceptResponse(self, rulename, response): - super(ResourceRegistriesCaching, self).interceptResponse(rulename, response, class_=StrongCaching) + return super(ResourceRegistriesCaching, self).interceptResponse(rulename, response, class_=StrongCaching) def modifyResponse(self, rulename, response): registry = getContext(self.published, IResourceRegistry) Modified: plone.app.caching/trunk/plone/app/caching/operations/utils.py ============================================================================== --- plone.app.caching/trunk/plone/app/caching/operations/utils.py (original) +++ plone.app.caching/trunk/plone/app/caching/operations/utils.py Mon Mar 8 06:19:11 2010 @@ -234,16 +234,22 @@ response.setHeader('ETag', etag, literal=1) # Specs say that Last-Modified MUST NOT be included in a 304 + # and Cache-Control/Expires MUST NOT be included unless they + # differ from the original response. We'll delete all, including + # Expires although technically it should be included. This is + # probably okay since in the original we only include Expires + # along with a Cache-Control and HTTP/1.1 clients will always + # use the later over any Expires header anyway. HTTP/1.0 clients + # never send conditional requests so they will never see this. + # # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html # - if lastModified is not None: - response.setHeader('Last-Modified', formatDateTime(lastModified)) - #if response.getHeader('Last-Modified'): - # del response.headers['last-modified'] - #if response.getHeader('Expires'): - # del response.headers['expires'] - #if response.getHeader('Cache-Control'): - # del response.headers['cache-control'] + if response.getHeader('Last-Modified'): + del response.headers['last-modified'] + if response.getHeader('Expires'): + del response.headers['expires'] + if response.getHeader('Cache-Control'): + del response.headers['cache-control'] response.setStatus(304) return u"" Modified: plone.app.caching/trunk/plone/app/caching/tests/test_operation_utils.py ============================================================================== --- plone.app.caching/trunk/plone/app/caching/tests/test_operation_utils.py (original) +++ plone.app.caching/trunk/plone/app/caching/tests/test_operation_utils.py Mon Mar 8 06:19:11 2010 @@ -481,15 +481,13 @@ now = datetime.datetime.now(dateutil.tz.tzlocal()) etag = "|foo|bar|" - nowFormatted = wsgiref.handlers.format_date_time(time.mktime(now.timetuple())) - body = notModified(published, request, response, etag=etag, lastModified=now) self.assertEquals(u"", body) self.assertEquals(etag, response.getHeader('ETag', literal=1)) - # Last-Modified not needed according to spec so needs fixing - #self.assertEquals(None, response.getHeader('Last-Modified')) - self.assertEquals(nowFormatted, response.getHeader('Last-Modified')) + self.assertEquals(None, response.getHeader('Last-Modified')) + self.assertEquals(None, response.getHeader('Expires')) + self.assertEquals(None, response.getHeader('Cache-Control')) self.assertEquals(304, response.getStatus()) class CacheCheckHelpersTest(unittest.TestCase): Modified: plone.app.caching/trunk/plone/app/caching/tests/test_profile_with_caching_proxy.py ============================================================================== --- plone.app.caching/trunk/plone/app/caching/tests/test_profile_with_caching_proxy.py (original) +++ plone.app.caching/trunk/plone/app/caching/tests/test_profile_with_caching_proxy.py Mon Mar 8 06:19:11 2010 @@ -28,7 +28,7 @@ TEST_FILE = pkg_resources.resource_filename('plone.app.caching.tests', 'test.gif') -class TestProfile(FunctionalTestCase): +class TestProfileWithCaching(FunctionalTestCase): """This test aims to exercise the caching operations expected from the `with-caching-proxy` profile. @@ -57,16 +57,6 @@ def beforeTearDown(self): setRequest(None) - # We'll reuse these tests from TestProfileBase - # but in the 'with-caching-proxy' context. - # No need to duplicate the code here. - # - # - test_composite_views() - # - # - test_resources() - # - # - test_stable_resources() - def test_composite_views(self): # This is a clone of the same test for 'without-caching-proxy' # Can we just call that test from this context? @@ -405,12 +395,14 @@ def test_stable_resources_resource_registries(self): # This is a clone of the same test for 'without-caching-proxy' # Can we just call that test from this context? + path = "/Sunburst%20Theme/public.css" # Request a ResourceRegistry resource cssregistry = self.portal.portal_css + path = cssregistry.absolute_url() + "/Sunburst%20Theme/public.css" now = datetime.datetime.now(dateutil.tz.tzlocal()) browser = Browser() - browser.open(cssregistry.absolute_url() + '/public.css') + browser.open(path) self.assertEquals('plone.stableResource', browser.headers['X-Cache-Rule']) self.assertEquals('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowserAndProxy @@ -419,31 +411,25 @@ timedelta = dateutil.parser.parse(browser.headers['Expires']) - now self.failUnless(timedelta > datetime.timedelta(seconds=31535990)) - # XXX - Fix this. This should just be a 304 response but Zope - # is adding extra headers and a body to it. - # # Request the ResourceRegistry resource again -- with IMS header to test 304 lastmodified = browser.headers['Last-Modified'] browser = Browser() browser.raiseHttpErrors = False browser.addHeader('If-Modified-Since', lastmodified) - browser.open(cssregistry.absolute_url() + '/public.css') + browser.open(path) self.assertEquals('plone.stableResource', browser.headers['X-Cache-Rule']) self.assertEquals('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) self.assertEquals('304 Not Modified', browser.headers['Status']) - # - # Zope is adding the body. Why? - #self.assertEquals('', browser.contents) - # - # These headers are added by Zope. Why? - #self.assertEquals(None, browser.headers.get('Expires')) - #self.assertEquals(None, browser.headers.get('Cache-Control')) + self.assertEquals('', browser.contents) + self.assertEquals(None, browser.headers.get('Last-Modified')) + self.assertEquals(None, browser.headers.get('Expires')) + self.assertEquals(None, browser.headers.get('Cache-Control')) # Request the ResourceRegistry resource -- with RR in debug mode now = datetime.datetime.now(dateutil.tz.tzlocal()) cssregistry.setDebugMode(True) browser = Browser() - browser.open(cssregistry.absolute_url() + '/public.css') + browser.open(path) self.assertEquals('plone.stableResource', browser.headers['X-Cache-Rule']) self.assertEquals('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should use doNotCache Modified: plone.app.caching/trunk/plone/app/caching/tests/test_profile_without_caching_proxy.py ============================================================================== --- plone.app.caching/trunk/plone/app/caching/tests/test_profile_without_caching_proxy.py (original) +++ plone.app.caching/trunk/plone/app/caching/tests/test_profile_without_caching_proxy.py Mon Mar 8 06:19:11 2010 @@ -28,7 +28,7 @@ TEST_FILE = pkg_resources.resource_filename('plone.app.caching.tests', 'test.gif') -class TestProfile(FunctionalTestCase): +class TestProfileWithoutCaching(FunctionalTestCase): """This test aims to exercise the caching operations expected from the `without-caching-proxy` profile. """ @@ -354,10 +354,11 @@ # Request a ResourceRegistry resource cssregistry = self.portal.portal_css + path = cssregistry.absolute_url() + "/Sunburst%20Theme/public.css" cssregistry.setDebugMode(False) now = datetime.datetime.now(dateutil.tz.tzlocal()) browser = Browser() - browser.open(cssregistry.absolute_url() + '/public.css') + browser.open(path) self.assertEquals('plone.stableResource', browser.headers['X-Cache-Rule']) self.assertEquals('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowserAndProxy @@ -366,31 +367,25 @@ timedelta = dateutil.parser.parse(browser.headers['Expires']) - now self.failUnless(timedelta > datetime.timedelta(seconds=31535990)) - # XXX - Fix this. This should just be a 304 response but Zope - # is adding extra headers and a body to it. - # # Request the ResourceRegistry resource again -- with IMS header to test 304 lastmodified = browser.headers['Last-Modified'] browser = Browser() browser.raiseHttpErrors = False browser.addHeader('If-Modified-Since', lastmodified) - browser.open(cssregistry.absolute_url() + '/public.css') + browser.open(path) self.assertEquals('plone.stableResource', browser.headers['X-Cache-Rule']) self.assertEquals('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) self.assertEquals('304 Not Modified', browser.headers['Status']) - # - # Zope is adding the body. Why? - #self.assertEquals('', browser.contents) - # - # These headers are added by Zope. Why? - #self.assertEquals(None, browser.headers.get('Expires')) - #self.assertEquals(None, browser.headers.get('Cache-Control')) + self.assertEquals('', browser.contents) + self.assertEquals(None, browser.headers.get('Last-Modified')) + self.assertEquals(None, browser.headers.get('Expires')) + self.assertEquals(None, browser.headers.get('Cache-Control')) # Request the ResourceRegistry resource -- with RR in debug mode now = datetime.datetime.now(dateutil.tz.tzlocal()) cssregistry.setDebugMode(True) browser = Browser() - browser.open(cssregistry.absolute_url() + '/public.css') + browser.open(path) self.assertEquals('plone.stableResource', browser.headers['X-Cache-Rule']) self.assertEquals('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should use doNotCache |