]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_cache: Support the caching of HEAD requests.
authorGraham Leggett <minfrin@apache.org>
Thu, 30 Sep 2010 23:25:15 +0000 (23:25 +0000)
committerGraham Leggett <minfrin@apache.org>
Thu, 30 Sep 2010 23:25:15 +0000 (23:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1003331 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/cache/mod_cache.c
modules/cache/mod_disk_cache.c

diff --git a/CHANGES b/CHANGES
index 9a92b5f677fdfbeed6ecf7463ef1211003e6d891..3c743cfb20635b2ae8c2a75065800c7a9a16069c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
 
 Changes with Apache 2.3.9
 
+  *) mod_cache: Support the caching of HEAD requests. [Graham Leggett]
+
   *) htcacheclean: Allow the option to round up file sizes to a given
      block size, improving the accuracy of disk usage. [Graham Leggett]
 
index 1313306d0605f102985a5c31b6490a3fedcb6211..d3f1929411c8d07cce9435aa75d45dc6892b25c9 100644 (file)
@@ -852,10 +852,6 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
          */
         reason = "No Last-Modified; Etag; Expires; Cache-Control:max-age or Cache-Control:s-maxage headers";
     }
-    else if (r->header_only && !cache->stale_handle) {
-        /* Forbid HEAD requests unless we have it cached already */
-        reason = "HTTP HEAD request";
-    }
     else if (!conf->store_nostore &&
              ap_cache_liststr(NULL, cc_out, "no-store", NULL)) {
         /* RFC2616 14.9.2 Cache-Control: no-store response
@@ -1039,10 +1035,6 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
      */
 
     /* 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) {
@@ -1051,7 +1043,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
             info = &cache->handle->cache_obj->info;
             rv = OK;
         }
-        else if (!r->header_only) {
+        else {
             /* Oh, well.  Toss it. */
             cache->provider->remove_entity(cache->stale_handle);
             /* Treat the request as if it wasn't conditional. */
@@ -1065,8 +1057,8 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
         }
     }
 
-    /* no cache handle, create a new entity only for non-HEAD requests */
-    if (!cache->handle && !r->header_only) {
+    /* no cache handle, create a new entity */
+    if (!cache->handle) {
         rv = cache_create_entity(cache, r, size, in);
         info = apr_pcalloc(r->pool, sizeof(cache_info));
         /* We only set info->status upon the initial creation. */
index 8c3402d8315ce5aaedb5225d46b4e99620dbefa7..5b483995a6877f3bd93866c72918196c449841f4 100644 (file)
@@ -391,6 +391,8 @@ static int create_entity(cache_handle_t *h, request_rec *r, const char *key, apr
     dobj->hdrs.file = header_file(r->pool, conf, dobj, key);
     dobj->vary.file = header_file(r->pool, conf, dobj, key);
 
+    dobj->disk_info.header_only = r->header_only;
+
     return OK;
 }
 
@@ -525,6 +527,14 @@ static int open_entity(cache_handle_t *h, request_rec *r, const char *key)
 
     apr_file_close(dobj->hdrs.fd);
 
+    /* Is this a cached HEAD request? */
+    if (dobj->disk_info.header_only && !r->header_only) {
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r->server,
+                 "disk_cache: HEAD request cached, non-HEAD requested, ignoring: %s",
+                 dobj->hdrs.file);
+        return DECLINED;
+    }
+
     /* Open the data file */
     if (dobj->disk_info.has_body) {
         flags = APR_READ | APR_BINARY;
@@ -999,6 +1009,7 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r)
     disk_info.status = h->cache_obj->info.status;
     disk_info.inode = dobj->disk_info.inode;
     disk_info.device = dobj->disk_info.device;
+    disk_info.header_only = dobj->disk_info.header_only;
 
     disk_info.name_len = strlen(dobj->name);