Title: [PATCH] mod_cache RFC compliance

Hello,

In order to accelerate the RFC compliance of mod_cache, I propose these two patches which fix two problems :
- It doesn't handle the Cache-Control directives (max-age, max-stale, min-fresh...) properly.
- It doesn't send a "If-Modified-Since" to avoid that the backend server sends every time a 200 response where a 304 would be enough.

Actually, we are waiting for these features to be implemented since http-2.0.43 so that we could put Apache in our production environment. I am not an Apache developper, so this is just a proposition, but I tested it and it seemed to work.


The cache_util.c patch deals with the first issue. First, the Cache-Control directive seems to be in the r->err_headers_out and not in the r->headers_out. Second, the following test seems useless :

        if ((-1 < smaxage && age < (smaxage - minfresh)) ||
          (-1 < maxage && age < (maxage + maxstale - minfresh)) ||
          (info->expire != APR_DATE_BAD &&
           age < (apr_time_sec(info->expire - info->date) + maxstale - minfresh))) {

because it is always true, no matter if max-age is set or not.
Let's take an example (I suppose here s-maxage, max-stale and min-fresh not set,
so smaxage = - 1, maxstale = 0 and minfresh = 0) :
- with age = 20, maxage = -1 (not set) and expire - date = 30, the second test
is FALSE. The third is TRUE. So the whole test is TRUE, the page is considered
to be fresh => no problem.
- with age = 20, maxage = 10 and expire - date = 30, the second test is FALSE,
but the third is still TRUE. So the whole test is TRUE, the page is considered
to be fresh => problem.


The mod_cache.c patch deals with the second issue. The info structure is never initialized, and even if it was, the info->lastmods and info->etag don't seem to be saved in the file when using mod_disk_cache. So I used the Etag and Last-Modified informations we can find in the r->headers_out and r->err_headers_out. I don't know if it's correct, but it seems to work now...

Thanks for looking to these patch and eventually integrate it in the next Apache release !

Thanks a lot for this really great product !


Thomas.


 

Attachment: mod_cache.patch
Description: Binary data

Attachment: cache_util.patch
Description: Binary data

Reply via email to