You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Nicholas Sherlock <n....@gmail.com> on 2009/04/24 07:41:32 UTC

[users@httpd] mod_cache sending document along with 304 Not Modified!

Hey everyone,

I'm having some real trouble getting mod_cache working correctly. I'm 
using mod_rewrite and PHP too. I have my document:

http://www.chickensmoothie.com/pet/1067395&bg=F1E9C8.jpg

My cache is set up like this:

CacheEnable disk /pet

In /pet/.htaccess I have this:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.jpg$ /pet.php?id=$1

/pet.php sends an ETag when it generates the document. If it gets a 
"If-None-Match" request header, it sends a "HTTP/1.0 304 Not Modified" 
response code, along with a custom header "X-CS-Caught-Late: yes" and 
exits. Otherwise, it sends a 200 code, a timestamp indicating when the 
document was generated (X-CS-Generated) along with the document.

What I expect will happen is that with the very first GET of the 
document, it will not be found in the disk cache. The request will be 
passed on to my pet.php script which will send the response along with 
an ETag. This works perfectly (IE7). Here's the request:

GET /pet/1067395&bg=F1E9C8.jpg HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, 
application/x-ms-application, application/vnd.ms-xpsdocument, 
application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, 
application/vnd.ms-powerpoint, application/msword, 
application/x-silverlight, application/x-shockwave-flash, */*
Accept-Language: en-nz
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; 
SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
Host: www.chickensmoothie.com
Connection: Keep-Alive

The server's response:

HTTP/1.1 200 OK
Date: Fri, 24 Apr 2009 05:33:36 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.5 with Suhosin-Patch
X-Powered-By: PHP/5.2.4-2ubuntu5.5
Cache-Control: max-age=7000, public
ETag: "ad7401c3ef76ef0532c687209f075abb"
X-CS-Generated: Fri, 24 Apr 2009 05:33:37 +0000
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/png
<document was sent here>

Now on the second request from IE, it correctly sends a conditional get 
with the ETag:

GET /pet/1067395&bg=F1E9C8.jpg HTTP/1.1
Accept: */*
Accept-Language: en-nz
Accept-Encoding: gzip, deflate
If-None-Match: "ad7401c3ef76ef0532c687209f075abb"
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; 
SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
Host: www.chickensmoothie.com
Connection: Keep-Alive

And the server gives the correct _headers_ back:

HTTP/1.0 304 Not Modified
Date: Fri, 24 Apr 2009 05:33:41 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.5 with Suhosin-Patch
Connection: close
ETag: "ad7401c3ef76ef0532c687209f075abb"
Cache-Control: max-age=7000, public
<document was sent here>

But Apache sends the document at the end of the 304 Not Modified 
response! This sort of defeats the purpose of this response code. You 
can see that the response is not generated by my backend code, because 
the custom header "X-CS-Caught-Late: yes" is not in the response.

Why is this happening? You can try it out on my live server, using the 
same URL as I did.

Cheers,
Nicholas Sherlock


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org