Commit 7159fa5c authored by Toby Dickenson's avatar Toby Dickenson

merged toby-cacheable-zmi-branch

parent 6b6c466a
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Image object that is stored in a file""" """Image object that is stored in a file"""
__version__='$Revision: 1.15 $'[11:-2] __version__='$Revision: 1.16 $'[11:-2]
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
from Globals import package_home from Globals import package_home
...@@ -21,9 +21,9 @@ from DateTime import DateTime ...@@ -21,9 +21,9 @@ from DateTime import DateTime
from time import time from time import time
from os import stat from os import stat
import Acquisition import Acquisition
import Globals
import os import os
class ImageFile(Acquisition.Explicit): class ImageFile(Acquisition.Explicit):
"""Image objects stored in external files.""" """Image objects stored in external files."""
...@@ -33,6 +33,13 @@ class ImageFile(Acquisition.Explicit): ...@@ -33,6 +33,13 @@ class ImageFile(Acquisition.Explicit):
_prefix=package_home(_prefix) _prefix=package_home(_prefix)
path = os.path.join(_prefix, path) path = os.path.join(_prefix, path)
self.path=path self.path=path
if Globals.DevelopmentMode:
# In development mode, shorter is handy
max_age = 60
else:
# In production mode, longer reduces latency
max_age = 600
self.cch = 'public,max-age=%d' % max_age
file=open(path, 'rb') file=open(path, 'rb')
data=file.read() data=file.read()
...@@ -52,6 +59,9 @@ class ImageFile(Acquisition.Explicit): ...@@ -52,6 +59,9 @@ class ImageFile(Acquisition.Explicit):
# HTTP If-Modified-Since header handling. This is duplicated # HTTP If-Modified-Since header handling. This is duplicated
# from OFS.Image.Image - it really should be consolidated # from OFS.Image.Image - it really should be consolidated
# somewhere... # somewhere...
RESPONSE.setHeader('Content-Type', self.content_type)
RESPONSE.setHeader('Last-Modified', self.lmh)
RESPONSE.setHeader('Cache-Control', self.cch)
header=REQUEST.get_header('If-Modified-Since', None) header=REQUEST.get_header('If-Modified-Since', None)
if header is not None: if header is not None:
header=header.split(';')[0] header=header.split(';')[0]
...@@ -72,8 +82,6 @@ class ImageFile(Acquisition.Explicit): ...@@ -72,8 +82,6 @@ class ImageFile(Acquisition.Explicit):
RESPONSE.setStatus(304) RESPONSE.setStatus(304)
return '' return ''
RESPONSE.setHeader('Content-Type', self.content_type)
RESPONSE.setHeader('Last-Modified', self.lmh)
f=open(self.path,'rb') f=open(self.path,'rb')
data=f.read() data=f.read()
f.close() f.close()
......
<dtml-unless zmi_embedded_css> <dtml-unless zmi_embedded_css>
<dtml-call "RESPONSE.setHeader('Content-Type','text/css')"> <dtml-call "RESPONSE.setHeader('Content-Type','text/css')">
<dtml-call "RESPONSE.setHeader('Cache-Control','public,max-age=3600')">
</dtml-unless> </dtml-unless>
h1 { h1 {
font-family: Verdana, Helvetica, sans-serif; font-family: Verdana, Helvetica, sans-serif;
......
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