On May 18, 2007, at 5:26 PM, Justin Erenkrantz wrote:

On 5/18/07, Ruediger Pluem <[EMAIL PROTECTED]> wrote:
> Well, because rv == !OK, wouldn't the CACHE_REMOVE_URL filter hit?
> That should do the dirty deed, no?  -- justin

No, as the CACHE_REMOVE_URL filter will only work if there is a
cache->handle or a cache->stale_handle. We have neither, as cache- >stale_handle is set to NULL in the case that the cached entity is *really* stale and we do
not create a new entity (and thus a cache->handle) in the HEAD case.

Well, let's not clear cache->stale_handle then.  How does the
following look?  -- justin


+1 !

Index: modules/cache/mod_cache.c
===================================================================
--- modules/cache/mod_cache.c   (revision 539607)
+++ modules/cache/mod_cache.c   (working copy)
@@ -477,8 +477,10 @@
        reason = "No Last-Modified, Etag, or Expires headers";
    }
    else if (r->header_only) {
-        /* HEAD requests */
-        reason = "HTTP HEAD request";
+        /* Forbid HEAD requests unless we have it cached already */
+        if (!cache->stale_handle) {
+            reason = "HTTP HEAD request";
+        }
    }
    else if (!conf->store_nostore &&
             ap_cache_liststr(NULL, cc_out, "no-store", NULL)) {
@@ -596,7 +598,12 @@
     * the headers).
     */

-    /* Did we have a stale cache entry that really is stale? */
+    /* Did we have a stale cache entry that really is stale?
+     *
+ * Note that for HEAD requests, we won't get the body, so for a stale
+     * HEAD request, we don't remove the entity - instead we let the
+     * CACHE_REMOVE_URL filter remove the stale item from the cache.
+     */
    if (cache->stale_handle) {
        if (r->status == HTTP_NOT_MODIFIED) {
            /* Oh, hey.  It isn't that stale!  Yay! */
@@ -604,7 +611,7 @@
            info = &cache->handle->cache_obj->info;
            rv = OK;
        }
-        else {
+        else if (!r->header_only) {
            /* Oh, well.  Toss it. */
            cache->provider->remove_entity(cache->stale_handle);
            /* Treat the request as if it wasn't conditional. */
@@ -612,8 +619,8 @@
        }
    }

-    /* no cache handle, create a new entity */
-    if (!cache->handle) {
+ /* no cache handle, create a new entity only for non-HEAD requests */
+    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. */


Reply via email to