I noticed that all of my static files were not returning Expires
headers, even though I set the correct tools.expires settings in the
config file:
[/static]
tools.staticdir.on = True
tools.staticdir.dir = "static"
tools.expires.on = True
tools.expires.secs = 1000
I looked over the source and found that cacheable responses never get
the "Expires" response header set! (Go ahead, check out the cherrypy/
lib/caching.py source file, very bottom)
I nailed down the problem to this commit:
http://www.cherrypy.org/changeset/1208
. Notice that the description of the commit is completely the opposite
of what the python revision is doing. The only time the 'Expires'
header gets set is if the response is a "noncacheable" object.
I think the problem is that the "expires" tool is trying to do three
different things simultaneously... make responses non-cacheable, make
responses expire immediately, and make responses expire in the
future.
Anyways, here's my patch. Unfortunately I don't have access to the
cherrypy trac page, so hopefully someone here will pick this up, and
fix as necessary.
patch for lib/caching.py:
http://pastebin.com/f23025149
patch for test/test_caching.py:
http://pastebin.com/m7852325b
viva la cherrypy.
- Jae Kwon