[ZCM] [ZC] 1727/ 2 Comment "AcceleratedHTTPCacheManager does not update Expires and Cache-Control: max-age header for "Not Modified" (304) responses"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Wed Mar 23 16:45:25 EST 2005


Issue #1727 Update (Comment) "AcceleratedHTTPCacheManager does not update Expires and Cache-Control: max-age header for "Not Modified" (304) responses"
 Status Pending, Zope/bug low
To followup, visit:
  http://www.zope.org/Collectors/Zope/1727

==============================================================
= Comment - Entry #2 by jensiboy on Mar 23, 2005 4:35 pm


Uploaded:  "Image_cache-headers-for-304.py.diff"
 - http://www.zope.org/Collectors/Zope/1727/Image_cache-headers-for-304.py.diff/view
The patch fixes the problem. I am not a python hacker, nor do I know zope very well. So, please proofread that stuff :)

jens

________________________________________
= Request - Entry #1 by Anonymous User on Mar 15, 2005 4:45 pm

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html says:
 <quote>
 10.3.5 304 Not Modified
 [...]
 The response MUST include the following header fields: 
 [...]
       - Expires, Cache-Control, and/or Vary, if the field-value might
         differ from that sent in any previous response for the same
         variant
 </quote>

The AcceleratedHTTPCacheManager does not update the Expires and Cache-Control field for 304 responses ("Not Modified").

Why is this important? Imagine the following very common scenario:
You have a caching proxy server in front of Zope, saye apache with mod_proxy. Say "Interval (Seconds)" is set to 20 in the HTTPCache in the ZMI (only 20, just for illustration):

On the first request for a file, the caching proxy server (here apache) asks something similar to this:
  $ telnet freifunk.net 8080
  Trying 195.234.229.105...
  Connected to freifunk.net.
  Escape character is '^]'.
  GET /freifunk/test-jens.txt HTTP/1.1
  Host: www.freifunk.net:8080

Here test-jens.txt is a file associated with the HTTPCache. So, Zope responds with:
  HTTP/1.1 200 OK
  Server: Zope/(unreleased version, python 2.3.4, linux2) ZServer/1.1 
  Plone/2.0.4
  Date: Tue, 08 Mar 2005 19:50:05 GMT
  Content-Length: 8
  Accept-Ranges: bytes
  -> Expires: Tue, 08 Mar 2005 19:50:25 GMT
  Last-Modified: Tue, 08 Mar 2005 19:50:05 GMT
  Etag:
  -> Cache-Control: max-age=20
  Content-Type: text/plain

After the 20sec (the caching interval) are over the apache-caching-proxy still has a copy of the file (here test-jens.txt). However, apache does not know if this file is still valid, since the 20 seconds are over. So it asks with a Conditional Get by means of the If-Modified-Since header field. Apache's request looks something like:
  $ telnet freifunk.net 8080
  Trying 195.234.229.105...
  Connected to freifunk.net.
  Escape character is '^]'.
  GET /freifunk/test-jens.txt HTTP/1.1
  Host: www.freifunk.net:8080
  -> If-Modified-Since: Tue, 08 Mar 2005 19:50:05 GMT

This the file was not changed in between, Zope answers:
  HTTP/1.1 304 Not Modified
  Server: Zope/(unreleased version, python 2.3.4, linux2) ZServer/1.1 
  Plone/2.0.4
  Date: Tue, 08 Mar 2005 19:51:52 GMT
  Content-Length: 8
  Accept-Ranges: bytes
  Last-Modified: Tue, 08 Mar 2005 07:50:15 GMT
  Etag:
  Content-Type: text/plain
  **N.B.: there is no updated Expires or Cache-Control field here**

So the next time the file (test-jens.txt) is requested, Apache again has to ask and gets a 304 response again. After this apache again has to ask, because the Expires and Cache-Control fields were note updated. This repeats infinitely. This means, that after the initial caching interval is over, Zope is swamped with Conditional GET requests (using the If-Modified-Since field).

If the header was reset with
  Cache-Control: max-age=20
  Expires: now+20
then Zope would be let alone for the caching interval again. This is how I read the RFC and imho this is also how it would make sense.

kind regards,

Jens

PS Please CC responses to nachtigall at web.de, if that is not done automatically by the Zope BTS. 
 


==============================================================



More information about the Zope-Collector-Monitor mailing list