Commit 5215c5db authored by 's avatar

Removed If-Modified-Since handling, since some clients apparently dont

handle 304 responses very well.
parent f2a7d664
...@@ -84,16 +84,15 @@ ...@@ -84,16 +84,15 @@
############################################################################## ##############################################################################
"""Image object that is stored in a file""" """Image object that is stored in a file"""
__version__='$Revision: 1.2 $'[11:-2] __version__='$Revision: 1.3 $'[11:-2]
from OFS.content_types import guess_content_type
from Globals import package_home from Globals import package_home
from Common import rfc1123_date from Common import rfc1123_date
from string import rfind, split from string import rfind, split
from DateTime import DateTime from DateTime import DateTime
from time import time from time import time
from os import stat from os import stat
import mimetypes
import Acquisition import Acquisition
...@@ -106,31 +105,33 @@ class ImageFile(Acquisition.Explicit): ...@@ -106,31 +105,33 @@ class ImageFile(Acquisition.Explicit):
_prefix=package_home(_prefix) _prefix=package_home(_prefix)
path='%s/%s' % (_prefix, path) path='%s/%s' % (_prefix, path)
self.path=path self.path=path
content_type, enc=mimetypes.guess_type(path)
file=open(path, 'rb')
data=file.read()
file.close()
content_type, enc=guess_content_type(path, data)
if content_type: if content_type:
self.content_type=content_type self.content_type=content_type
else: else:
self.content_type='image/%s' % path[rfind(path,'.')+1:] self.content_type='image/%s' % path[rfind(path,'.')+1:]
self.__name__=path[rfind(path,'/')+1:] self.__name__=path[rfind(path,'/')+1:]
# Determine a reasonable last-modification time
# to support aggressive image caching.
self.lmt=float(stat(path)[8]) or time() self.lmt=float(stat(path)[8]) or time()
self.lmh=rfc1123_date(self.lmt) self.lmh=rfc1123_date(self.lmt)
def _init_headers(self, request, response): def _init_headers(self, request, response):
# attempt aggressive caching! # Waaa... trying to cache aggressively seems to cause problems :(
ms=request.get_header('If-Modified-Since', None) #
if ms is not None: # ms=request.get_header('If-Modified-Since', None)
# Netscape inexplicably adds a length component # if ms is not None:
# to the IMS header. Waaaa.... # ms=split(ms, ';')[0]
ms=split(ms, ';')[0] # mst=DateTime(ms).timeTime()
mst=DateTime(ms).timeTime() # if mst >= self.lmt:
if mst >= self.lmt: # response.setStatus(304)
response.setStatus(304) # return response
return response # response.setHeader('Expires', rfc1123_date(time()+86400.0))
response.setHeader('Content-Type', self.content_type) response.setHeader('Content-Type', self.content_type)
response.setHeader('Last-Modified', self.lmh) response.setHeader('Last-Modified', self.lmh)
response.setHeader('Expires', rfc1123_date(time()+86400.0))
def index_html(self, REQUEST, RESPONSE): def index_html(self, REQUEST, RESPONSE):
"""Default document""" """Default document"""
......
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