From a814f226ab85a053c92c387fa6f3bf3733510c2d Mon Sep 17 00:00:00 2001 From: Bill Stoddard Date: Mon, 25 Nov 2002 17:40:23 +0000 Subject: [PATCH] Log reason for cache decline. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97646 13f79535-47bb-0310-9956-ffa450edef68 --- modules/experimental/mod_cache.c | 72 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/modules/experimental/mod_cache.c b/modules/experimental/mod_cache.c index 5a0de969ba..9750b8c3a3 100644 --- a/modules/experimental/mod_cache.c +++ b/modules/experimental/mod_cache.c @@ -460,7 +460,8 @@ static int cache_in_filter(ap_filter_t *f, apr_bucket_brigade *in) info = cache->info; } else { - + char *reason = NULL; + apr_pool_t *p = r->pool; /* * Pass Data to Cache * ------------------ @@ -526,45 +527,64 @@ static int cache_in_filter(ap_filter_t *f, apr_bucket_brigade *in) * a whole lot of conditions that prevent us from caching this data. * They are tested here one by one to be clear and unambiguous. */ - - /* RFC2616 13.4 we are allowed to cache 200, 203, 206, 300, 301 or 410 - * We don't cache 206, because we don't (yet) cache partial responses. - * We include 304 Not Modified here too as this is the origin server - * telling us to serve the cached copy. - */ - if ((r->status != HTTP_OK && r->status != HTTP_NON_AUTHORITATIVE - && r->status != HTTP_MULTIPLE_CHOICES - && r->status != HTTP_MOVED_PERMANENTLY - && r->status != HTTP_NOT_MODIFIED) + if (r->status != HTTP_OK && r->status != HTTP_NON_AUTHORITATIVE + && r->status != HTTP_MULTIPLE_CHOICES + && r->status != HTTP_MOVED_PERMANENTLY + && r->status != HTTP_NOT_MODIFIED) { + /* RFC2616 13.4 we are allowed to cache 200, 203, 206, 300, 301 or 410 + * We don't cache 206, because we don't (yet) cache partial responses. + * We include 304 Not Modified here too as this is the origin server + * telling us to serve the cached copy. + */ + reason = apr_pstrcat(p, "Response status %d", r->status); + } + else if (exps != NULL && exp == APR_DATE_BAD) { /* if a broken Expires header is present, don't cache it */ - || (exps != NULL && exp == APR_DATE_BAD) + reason = apr_pstrcat(p, "Broken expires header %s", exp); + } + else if (r->args && exps == NULL) { /* if query string present but no expiration time, don't cache it * (RFC 2616/13.9) */ - || (r->args && exps == NULL) + reason = "Query string present but no expires header"; + } + else if (r->status == HTTP_NOT_MODIFIED && (NULL == cache->handle)) { /* if the server said 304 Not Modified but we have no cache * file - pass this untouched to the user agent, it's not for us. */ - || (r->status == HTTP_NOT_MODIFIED && (NULL == cache->handle)) + reason = "HTTP Status 304 Not Modified"; + } + else if (r->status == HTTP_OK && lastmods == NULL && etag == NULL + && (conf->no_last_mod_ignore ==0)) { /* 200 OK response from HTTP/1.0 and up without a Last-Modified * header/Etag */ /* XXX mod-include clears last_modified/expires/etags - this * is why we have an optional function for a key-gen ;-) */ - || (r->status == HTTP_OK && lastmods == NULL && etag == NULL - && (conf->no_last_mod_ignore ==0)) + reason = "No Last-Modified or Etag header"; + } + else if (r->header_only) { /* HEAD requests */ - || r->header_only + reason = "HTTP HEAD request"; + } + else if (ap_cache_liststr(NULL, cc_out, "no-store", NULL)) { /* RFC2616 14.9.2 Cache-Control: no-store response * indicating do not cache, or stop now if you are * trying to cache it */ - || ap_cache_liststr(NULL, cc_out, "no-store", NULL) + reason = "Cache-Control: no-store present"; + } + else if (ap_cache_liststr(NULL, cc_out, "private", NULL)) { /* RFC2616 14.9.1 Cache-Control: private * this object is marked for this user's eyes only. Behave * as a tunnel. */ - || ap_cache_liststr(NULL, cc_out, "private", NULL) + reason = "Cache-Control: private present"; + } + else if (apr_table_get(r->headers_in, "Authorization") != NULL + && !(ap_cache_liststr(NULL, cc_out, "s-maxage", NULL) + || ap_cache_liststr(NULL, cc_out, "must-revalidate", NULL) + || ap_cache_liststr(NULL, cc_out, "public", NULL))) { /* RFC2616 14.8 Authorisation: * if authorisation is included in the request, we don't cache, * but we can cache if the following exceptions are true: @@ -572,16 +592,16 @@ static int cache_in_filter(ap_filter_t *f, apr_bucket_brigade *in) * 2) If Cache-Control: must-revalidate is included * 3) If Cache-Control: public is included */ - || (apr_table_get(r->headers_in, "Authorization") != NULL - && !(ap_cache_liststr(NULL, cc_out, "s-maxage", NULL) - || ap_cache_liststr(NULL, cc_out, "must-revalidate", NULL) - || ap_cache_liststr(NULL, cc_out, "public", NULL))) + reason = "Authorization required"; + } + else if (r->no_cache) { /* or we've been asked not to cache it above */ - || r->no_cache) { + reason = "no_cache present"; + } + if (reason) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, - "cache: response is not cachable"); - + "cache: response not cached. Reason: %s", reason); /* remove this object from the cache * BillS Asks.. Why do we need to make this call to remove_url? * leave it in for now.. -- 2.40.0