Commits

Robert Brewer committed 1c9fa1e

Fix for #728 (tools.expires doesn't set a past-date header when secs=0).

Comments (0)

Files changed (2)

cherrypy/lib/caching.py

     number of seconds between response.time and when the response should
     expire. The 'Expires' header will be set to (response.time + secs).
     
-    If 'secs' is zero, the following "cache prevention" headers are also set:
+    If 'secs' is zero, the 'Expires' header is set one year in the past, and
+    the following "cache prevention" headers are also set:
        'Pragma': 'no-cache'
        'Cache-Control': 'no-cache, must-revalidate'
     
             if cherrypy.request.protocol >= (1, 1):
                 if force or "Cache-Control" not in headers:
                     headers["Cache-Control"] = "no-cache, must-revalidate"
-        
-        expiry = http.HTTPDate(response.time + secs)
+            # Set an explicit Expires date in the past.
+            expiry = http.HTTPDate(1169942400.0)
+        else:
+            expiry = http.HTTPDate(response.time + secs)
         if force or "Expires" not in headers:
             headers["Expires"] = expiry

cherrypy/test/test_caching.py

         self.assertHeader("Pragma", "no-cache")
         if cherrypy.server.protocol_version == "HTTP/1.1":
             self.assertHeader("Cache-Control", "no-cache, must-revalidate")
-        d = self.assertHeader("Date")
-        self.assertHeader("Expires", d)
+        self.assertHeader("Expires", "Sun, 28 Jan 2007 00:00:00 GMT")
         
         # static content should now have "cache prevention" headers
         self.getPage("/expires/index.html")
         self.assertHeader("Pragma", "no-cache")
         if cherrypy.server.protocol_version == "HTTP/1.1":
             self.assertHeader("Cache-Control", "no-cache, must-revalidate")
-        d = self.assertHeader("Date")
-        self.assertHeader("Expires", d)
+        self.assertHeader("Expires", "Sun, 28 Jan 2007 00:00:00 GMT")
         
         # the cacheable handler should now have "cache prevention" headers
         self.getPage("/expires/cacheable")
         self.assertHeader("Pragma", "no-cache")
         if cherrypy.server.protocol_version == "HTTP/1.1":
             self.assertHeader("Cache-Control", "no-cache, must-revalidate")
-        d = self.assertHeader("Date")
-        self.assertHeader("Expires", d)
+        self.assertHeader("Expires", "Sun, 28 Jan 2007 00:00:00 GMT")
         
         self.getPage('/expires/dynamic')
         self.assertBody("D-d-d-dynamic!")
         self.assertHeader("Pragma", "no-cache")
         if cherrypy.server.protocol_version == "HTTP/1.1":
             self.assertHeader("Cache-Control", "no-cache, must-revalidate")
-        d = self.assertHeader("Date")
-        self.assertHeader("Expires", d)
+        self.assertHeader("Expires", "Sun, 28 Jan 2007 00:00:00 GMT")
     
     def testLastModified(self):
         self.getPage("/a.gif")