Commit 76193296 authored by Sander Striker's avatar Sander Striker
Browse files

Improve caching a bit more...

* 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
parent c0e97969
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -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 */
}

+10 −37
Original line number Diff line number Diff line
@@ -98,40 +98,10 @@ 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);
    if (auth) {
        return DECLINED;
    }
    }

    /*
     * Try to serve this request from the cache.
@@ -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