Commit ef5f7ab3 authored by 's avatar

Added If-Modified-Since handling.

parent 50e6f2c0
......@@ -84,7 +84,7 @@
##############################################################################
"""Image object that is stored in a file"""
__version__='$Revision: 1.4 $'[11:-2]
__version__='$Revision: 1.5 $'[11:-2]
from OFS.content_types import guess_content_type
from Globals import package_home
......@@ -119,23 +119,21 @@ class ImageFile(Acquisition.Explicit):
self.lmh=rfc1123_date(self.lmt)
def _init_headers(self, request, response):
# Waaa... trying to cache aggressively seems to cause problems :(
#
# ms=request.get_header('If-Modified-Since', None)
# if ms is not None:
# ms=split(ms, ';')[0]
# mst=DateTime(ms).timeTime()
# if mst >= self.lmt:
# response.setStatus(304)
# return response
# response.setHeader('Expires', rfc1123_date(time()+86400.0))
# Attempt to handle If-Modified-Since headers.
ms=request.get_header('If-Modified-Since', None)
if ms is not None:
ms=string.split(ms, ';')[0]
ms=DateTime(ms).timeTime()
if self.lmt > ms:
RESPONSE.setStatus(304)
return RESPONSE
response.setHeader('Content-Type', self.content_type)
# response.setHeader('Last-Modified', self.lmh)
response.setHeader('Last-Modified', self.lmh)
def index_html(self, REQUEST, RESPONSE):
"""Default document"""
self._init_headers(REQUEST, RESPONSE)
if self._init_headers(REQUEST, RESPONSE):
return ''
f=open(self.path,'rb')
data=f.read()
f.close()
......
......@@ -84,7 +84,7 @@
##############################################################################
"""Image object"""
__version__='$Revision: 1.74 $'[11:-2]
__version__='$Revision: 1.75 $'[11:-2]
import Globals, string, struct, content_types
from OFS.content_types import guess_content_type
......@@ -170,6 +170,16 @@ class File(Persistent,Implicit,PropertyManager,
Returns the contents of the file or image. Also, sets the
Content-Type HTTP header to the objects content type.
"""
# Attempt to handle If-Modified-Since headers.
ms=REQUEST.get_header('If-Modified-Since', None)
if ms is not None:
ms=string.split(ms, ';')[0]
ms=DateTime(ms).timeTime()
if self._p_mtime > ms:
RESPONSE.setStatus(304)
return RESPONSE
if self.precondition and hasattr(self,self.precondition):
# Grab whatever precondition was defined and then
# execute it. The precondition will raise an exception
......@@ -179,8 +189,8 @@ class File(Persistent,Implicit,PropertyManager,
c(REQUEST['PARENTS'][1],REQUEST)
else:
c()
RESPONSE.setHeader('content-type', self.content_type)
# RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Content-Type', self.content_type)
return self.data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment