httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niklas Edmundsson <ni...@acc.umu.se>
Subject Re: mod_cache: 304 on HEAD (bug 41230)
Date Wed, 11 Apr 2007 12:16:04 GMT
On Wed, 11 Apr 2007, Niklas Edmundsson wrote:

> Would the correct fix be to check for r->header_only in cache_select(), or 
> are there even more funky stuff going on? You don't want the cached object to 
> be removed just because you got a HEAD request when it really isn't stale but 
> just in need of revalidation. Ideally the HEAD request would cause the object 
> to be revalidated if possible, but we can live with head requests just doing 
> fallback without touching the cache.
>
> I can whip up a patch for it, but I suspect that you guys are more clued on 
> the deep magic involved :)

Looking a bit further, I think that something like this would actually 
be enough:
-----------8<--------------
--- mod_cache.c.orig	2007-04-11 13:29:14.000000000 +0200
+++ mod_cache.c	2007-04-11 14:06:29.000000000 +0200
@@ -456,7 +456,7 @@ static int cache_save_filter(ap_filter_t
           */
          reason = "No Last-Modified, Etag, or Expires headers";
      }
-    else if (r->header_only) {
+    else if (r->header_only && !cache->stale_handle) {
          /* HEAD requests */
          reason = "HTTP HEAD request";
      }
@@ -589,11 +589,12 @@ static int cache_save_filter(ap_filter_t
              cache->provider->remove_entity(cache->stale_handle);
              /* Treat the request as if it wasn't conditional. */
              cache->stale_handle = NULL;
+            rv = !OK;
          }
      }

-    /* no cache handle, create a new entity */
-    if (!cache->handle) {
+    /* no cache handle, create a new entity only for non-HEAD request */
+    if (!cache->handle && !r->header_only) {
          rv = cache_create_entity(r, size);
          info = apr_pcalloc(r->pool, sizeof(cache_info));
          /* We only set info->status upon the initial creation. */
-----------8<--------------

If I have understood things right this would:
- Accept revalidations even though it's a HEAD if the object wasn't
   stale.
- Bail out if the object is stale and it's a HEAD.

I haven't tried it yet though, I'm just trying to get a grasp of 
things. I have no clue on whether other things would break due to the 
fact that it's revalidated based on a HEAD instead of a GET, for 
example.

/Nikke
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  Niklas Edmundsson, Admin @ {acc,hpc2n}.umu.se      |     nikke@acc.umu.se
---------------------------------------------------------------------------
  I am Mr. T of Borg. I pity da fool that resists me.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Mime
View raw message