summaryrefslogtreecommitdiff
path: root/modules/cache/cache_util.c
diff options
context:
space:
mode:
authorStefan Fritsch <sf@sfritsch.de>2011-12-27 19:43:09 +0100
committerStefan Fritsch <sf@sfritsch.de>2011-12-27 19:43:09 +0100
commit5b56d06a01a150fc9685e6f913774be3f9deb49f (patch)
tree9fbfbe0313b782941f1c2c4d3cb5203817144108 /modules/cache/cache_util.c
parent498ea95018b369e62646a98c7d7d5413b56e170c (diff)
downloadapache2-5b56d06a01a150fc9685e6f913774be3f9deb49f.tar.gz
Upstream tarball 2.2.19upstream/2.2.19
Diffstat (limited to 'modules/cache/cache_util.c')
-rw-r--r--modules/cache/cache_util.c70
1 files changed, 65 insertions, 5 deletions
diff --git a/modules/cache/cache_util.c b/modules/cache/cache_util.c
index cb3d5653..14c1165e 100644
--- a/modules/cache/cache_util.c
+++ b/modules/cache/cache_util.c
@@ -338,6 +338,64 @@ CACHE_DECLARE(apr_status_t) ap_cache_remove_lock(cache_server_conf *conf,
return apr_file_remove(lockname, r->pool);
}
+CACHE_DECLARE(int) ap_cache_check_allowed(request_rec *r) {
+ const char *cc_req;
+ const char *pragma;
+ cache_server_conf *conf =
+ (cache_server_conf *)ap_get_module_config(r->server->module_config,
+ &cache_module);
+
+ /*
+ * At this point, we may have data cached, but the request may have
+ * specified that cached data may not be used in a response.
+ *
+ * This is covered under RFC2616 section 14.9.4 (Cache Revalidation and
+ * Reload Controls).
+ *
+ * - RFC2616 14.9.4 End to end reload, Cache-Control: no-cache, or Pragma:
+ * no-cache. The server MUST NOT use a cached copy when responding to such
+ * a request.
+ *
+ * - RFC2616 14.9.2 What May be Stored by Caches. If Cache-Control:
+ * no-store arrives, do not serve from the cache.
+ */
+
+ /* 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)) {
+
+ if (!conf->ignorecachecontrol) {
+ return 0;
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
+ "Incoming request is asking for an uncached version of "
+ "%s, but we have been configured to ignore it and serve "
+ "cached content anyway", r->unparsed_uri);
+ }
+ }
+
+ if (ap_cache_liststr(NULL, cc_req, "no-store", NULL)) {
+
+ if (!conf->ignorecachecontrol) {
+ /* We're not allowed to serve a cached copy */
+ return 0;
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
+ "Incoming request is asking for a no-store version of "
+ "%s, but we have been configured to ignore it and serve "
+ "cached content anyway", r->unparsed_uri);
+ }
+ }
+
+ return 1;
+}
+
+
CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
request_rec *r)
{
@@ -360,10 +418,11 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
* We now want to check if our cached data is still fresh. This depends
* on a few things, in this order:
*
- * - RFC2616 14.9.4 End to end reload, Cache-Control: no-cache. no-cache in
- * either the request or the cached response means that we must
- * revalidate the request unconditionally, overriding any expiration
- * mechanism. It's equivalent to max-age=0,must-revalidate.
+ * - RFC2616 14.9.4 End to end reload, Cache-Control: no-cache. no-cache
+ * in either the request or the cached response means that we must
+ * perform the request unconditionally, and ignore cached content. We
+ * should never reach here, but if we do, mark the content as stale,
+ * as this is the best we can do.
*
* - RFC2616 14.32 Pragma: no-cache This is treated the same as
* Cache-Control: no-cache.
@@ -403,7 +462,8 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
"Incoming request is asking for a uncached version of "
- "%s, but we know better and are ignoring it",
+ "%s, but we have been configured to ignore it and "
+ "serve a cached response anyway",
r->unparsed_uri);
}