[CMF-checkins] CVS: Products/CMFCore - FSImage.py:1.14.18.7

Tres Seaver tseaver at palladion.com
Wed Jun 8 09:16:20 EDT 2005


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv12605/CMFCore

Modified Files:
      Tag: CMF-1_4-branch
	FSImage.py 
Log Message:


  - Set cache headers in 304 responses from FSImage / FSFile
    (http://zope.org/Collectors/355)


=== Products/CMFCore/FSImage.py 1.14.18.6 => 1.14.18.7 ===
--- Products/CMFCore/FSImage.py:1.14.18.6	Mon Apr 25 16:06:49 2005
+++ Products/CMFCore/FSImage.py	Wed Jun  8 09:15:49 2005
@@ -94,8 +94,11 @@
         """
         self._updateFromFS()
         data = self._data
+        data_len = len(data)
+        last_mod = self._file_mod_time
+        status = 200
         # HTTP If-Modified-Since header handling.
-        header=REQUEST.get_header('If-Modified-Since', None)
+        header = REQUEST.get_header('If-Modified-Since', None)
         if header is not None:
             header=string.split(header, ';')[0]
             # Some proxies seem to send invalid date strings for this
@@ -104,26 +107,26 @@
             # with common servers such as Apache (which can usually
             # understand the screwy date string as a lucky side effect
             # of the way they parse it).
-            try:    mod_since=long(DateTime(header).timeTime())
-            except: mod_since=None
+            try:
+                mod_since = long(DateTime(header).timeTime())
+            except:
+                mod_since = None
+
             if mod_since is not None:
-                last_mod = self._file_mod_time
                 if last_mod > 0 and last_mod <= mod_since:
-                    # Set header values since apache caching will return
-                    # Content-Length of 0 in response if size is not set here
-                    RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod))
-                    RESPONSE.setHeader('Content-Type', self.content_type)
-                    RESPONSE.setHeader('Content-Length', len(data))
-                    RESPONSE.setStatus(304)
-                    return ''
+                    status = 304
+                    data = ''
 
-        #Last-Modified will get stomped on by a cache policy it there is one set....
-        RESPONSE.setHeader('Last-Modified', rfc1123_date(self._file_mod_time))
+        #Last-Modified will get stomped on by a cache policy it there is
+        #one set....
+        RESPONSE.setStatus(status)
+        RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod))
         RESPONSE.setHeader('Content-Type', self.content_type)
-        RESPONSE.setHeader('Content-Length', len(data))
+        RESPONSE.setHeader('Content-Length', data_len)
 
-        #There are 2 Cache Managers which can be in play....need to decide which to use
-        #to determine where the cache headers are decided on.
+        #There are 2 Cache Managers which can be in play....
+        #need to decide which to use to determine where the cache headers
+        #are decided on.
         if self.ZCacheable_getManager() is not None:
             self.ZCacheable_set(None)
         else:



More information about the CMF-checkins mailing list