From: Graham Leggett Date: Thu, 30 Sep 2010 23:25:15 +0000 (+0000) Subject: mod_cache: Support the caching of HEAD requests. X-Git-Tag: 2.3.9~377 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44b825b72c706977f38148281dd9643e5809a0e0;p=thirdparty%2Fapache%2Fhttpd.git mod_cache: Support the caching of HEAD requests. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1003331 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 9a92b5f677f..3c743cfb206 100644 --- 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] diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index 1313306d060..d3f1929411c 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -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. */ diff --git a/modules/cache/mod_disk_cache.c b/modules/cache/mod_disk_cache.c index 8c3402d8315..5b483995a68 100644 --- a/modules/cache/mod_disk_cache.c +++ b/modules/cache/mod_disk_cache.c @@ -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);