]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Improve caching a bit more...
authorSander Striker <striker@apache.org>
Tue, 8 Mar 2005 02:35:50 +0000 (02:35 +0000)
committerSander Striker <striker@apache.org>
Tue, 8 Mar 2005 02:35:50 +0000 (02:35 +0000)
* modules/cache/cache_util.c

  (ap_cache_check_freshness): On Cache-Control/Pragma no-cache force
   revalidation by marking the resource as stale.  Unless IgnoreCacheControl
   is set ofcourse.

* modules/cache/mod_cache.c

  (cache_url_handler): Remove Cache-Control/Pragma no-cache check and
   accompagnying comment.

  (cache_save_filter): Move FIXME comment to the correct location.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@156480 13f79535-47bb-0310-9956-ffa450edef68

modules/cache/cache_util.c
modules/cache/mod_cache.c

index cb27e653c95dc80eb008984bad9f1654ad0de2c6..9bebf89c16e55f236499295e8742e8d21c9564e9 100644 (file)
@@ -116,6 +116,7 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
     apr_int64_t age, maxage_req, maxage_cresp, maxage, smaxage, maxstale;
     apr_int64_t minfresh;
     const char *cc_cresp, *cc_req;
+    const char *pragma;
     const char *agestr = NULL;
     const char *expstr = NULL;
     char *val;
@@ -154,8 +155,27 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
      * entity, and it's value is in the past, it has expired.
      * 
      */
+
     /* This value comes from the client's initial request. */
     cc_req = apr_table_get(r->headers_in, "Cache-Control");
+    pragma = apr_table_get(r->headers_in, "Pragma");
+
+    if (ap_cache_liststr(NULL, pragma, "no-cache", NULL)
+        || ap_cache_liststr(NULL, cc_req, "no-cache", NULL)) {
+        cache_server_conf *conf =
+          (cache_server_conf *)ap_get_module_config(r->server->module_config,
+                                                    &cache_module);
+
+        if (!conf->ignorecachecontrol) {
+           /* Treat as stale, causing revalidation */
+           return 0;
+       }
+
+        ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
+                     "Incoming request may be asking for a uncached version of "
+                     "%s, but we know better and are ignoring it",
+                     r->unparsed_uri);
+    }
 
     /* These come from the cached entity. */
     cc_cresp = apr_table_get(h->resp_hdrs, "Cache-Control");
@@ -188,8 +208,7 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
     if (cc_cresp && ap_cache_liststr(r->pool, cc_cresp, "max-age", &val)) {
         maxage_cresp = apr_atoi64(val);
     }
-    else
-    {
+    else {
         maxage_cresp = -1;
     }
 
@@ -279,6 +298,7 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
         }
         return 1;    /* Cache object is fresh (enough) */
     }
+
     return 0;        /* Cache object is stale */
 }
 
index 282447d424ca48a02c641fce72f938cbee2d688c..5da2797108c76cc6b0bfc11b91ec3840b0cf4369 100644 (file)
@@ -98,39 +98,9 @@ static int cache_url_handler(request_rec *r, int lookup)
 
     /* First things first - does the request allow us to return
      * cached information at all? If not, just decline the request.
-     *
-     * Note that there is a big difference between not being allowed
-     * to cache a response (no-store) and not being allowed to return
-     * a cached request without revalidation (max-age=0).
-     *
-     * Serving from a cache is forbidden under the following circumstances:
-     *
-     * - RFC2616 14.9.1 Cache-Control: no-cache
-     * - Pragma: no-cache
-     * - Any requests requiring authorization.
-     *
-     * Updating a cache is forbidden under the following circumstances:
-     * - RFC2616 14.9.2 Cache-Control: no-store
      */
-    if (conf->ignorecachecontrol == 1 && auth == NULL) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                     "incoming request may be asking for a uncached version of "
-                     "%s, but we know better and are ignoring it", url);
-    }
-    else {
-        const char *pragma, *cc_in;
-
-        pragma = apr_table_get(r->headers_in, "Pragma");
-        cc_in = apr_table_get(r->headers_in, "Cache-Control");
-
-        if (auth != NULL ||
-            ap_cache_liststr(NULL, pragma, "no-cache", NULL) ||
-            ap_cache_liststr(NULL, cc_in, "no-cache", NULL)) {
-            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                         "cache: no-cache or authorization forbids caching "
-                         "of %s", url);
-            return DECLINED;
-        }
+    if (auth) {
+        return DECLINED;
     }
 
     /*
@@ -271,10 +241,6 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
     /* If the request has Cache-Control: no-store from RFC 2616, don't store
      * unless CacheStoreNoStore is active.
      */
-    /* FIXME: The Cache-Control: no-store could have come in on a 304,
-     * FIXME: while the original request wasn't conditional.  IOW, we made the
-     * FIXME: the request conditional earlier to revalidate our cached response.
-     */
     cc_in = apr_table_get(r->headers_in, "Cache-Control");
     if (r->no_cache ||
         (!conf->store_nostore &&
@@ -426,7 +392,13 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
              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 */
+         * trying to cache it.
+         */
+        /* FIXME: The Cache-Control: no-store could have come in on a 304,
+         * FIXME: while the original request wasn't conditional.  IOW, we
+         * FIXME:  made the the request conditional earlier to revalidate
+         * FIXME: our cached response.
+         */
         reason = "Cache-Control: no-store present";
     }
     else if (!conf->store_private &&
@@ -435,6 +407,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
          * this object is marked for this user's eyes only. Behave
          * as a tunnel.
          */
+        /* FIXME: See above (no-store) */
         reason = "Cache-Control: private present";
     }
     else if (apr_table_get(r->headers_in, "Authorization") != NULL