summaryrefslogtreecommitdiff
path: root/modules/cache
diff options
context:
space:
mode:
authorStefan Fritsch <sf@sfritsch.de>2011-12-27 19:42:33 +0100
committerStefan Fritsch <sf@sfritsch.de>2011-12-27 19:42:33 +0100
commitad14e19ad0400e289b06fb7728aea815e6ed49be (patch)
treebd29489cafb04b303940169ae7b00c1171a5a34c /modules/cache
parent02a0e3b89d2ea1b984365e692c910668d75c6dcd (diff)
downloadapache2-ad14e19ad0400e289b06fb7728aea815e6ed49be.tar.gz
Upstream tarball 2.2.12upstream/2.2.12
Diffstat (limited to 'modules/cache')
-rw-r--r--modules/cache/mod_cache.c26
-rw-r--r--modules/cache/mod_disk_cache.c23
-rw-r--r--modules/cache/mod_mem_cache.c11
3 files changed, 53 insertions, 7 deletions
diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c
index 27df70d4..a35b2abc 100644
--- a/modules/cache/mod_cache.c
+++ b/modules/cache/mod_cache.c
@@ -440,7 +440,28 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
* We include 304 Not Modified here too as this is the origin server
* telling us to serve the cached copy.
*/
- reason = apr_psprintf(p, "Response status %d", r->status);
+ if (exps != NULL || cc_out != NULL) {
+ /* We are also allowed to cache any response given that it has a
+ * valid Expires or Cache Control header. If we find a either of
+ * those here, we pass request through the rest of the tests. From
+ * the RFC:
+ *
+ * A response received with any other status code (e.g. status
+ * codes 302 and 307) MUST NOT be returned in a reply to a
+ * subsequent request unless there are cache-control directives or
+ * another header(s) that explicitly allow it. For example, these
+ * include the following: an Expires header (section 14.21); a
+ * "max-age", "s-maxage", "must-revalidate", "proxy-revalidate",
+ * "public" or "private" cache-control directive (section 14.9).
+ */
+ }
+ else {
+ reason = apr_psprintf(p, "Response status %d", r->status);
+ }
+ }
+
+ if (reason) {
+ /* noop */
}
else if (exps != NULL && exp == APR_DATE_BAD) {
/* if a broken Expires header is present, don't cache it */
@@ -519,6 +540,9 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
"*", NULL)) {
reason = "Vary header contains '*'";
}
+ else if (apr_table_get(r->subprocess_env, "no-cache") != NULL) {
+ reason = "environment variable 'no-cache' is set";
+ }
else if (r->no_cache) {
/* or we've been asked not to cache it above */
reason = "r->no_cache present";
diff --git a/modules/cache/mod_disk_cache.c b/modules/cache/mod_disk_cache.c
index 4148b373..70a804b8 100644
--- a/modules/cache/mod_disk_cache.c
+++ b/modules/cache/mod_disk_cache.c
@@ -357,6 +357,10 @@ static int open_entity(cache_handle_t *h, request_rec *r, const char *key)
static int error_logged = 0;
disk_cache_conf *conf = ap_get_module_config(r->server->module_config,
&disk_cache_module);
+#ifdef APR_SENDFILE_ENABLED
+ core_dir_config *coreconf = ap_get_module_config(r->per_dir_config,
+ &core_module);
+#endif
apr_finfo_t finfo;
cache_object_t *obj;
cache_info *info;
@@ -452,7 +456,12 @@ static int open_entity(cache_handle_t *h, request_rec *r, const char *key)
/* Open the data file */
flags = APR_READ|APR_BINARY;
#ifdef APR_SENDFILE_ENABLED
- flags |= APR_SENDFILE_ENABLED;
+ /* When we are in the quick handler we don't have the per-directory
+ * configuration, so this check only takes the globel setting of
+ * the EnableSendFile directive into account.
+ */
+ flags |= ((coreconf->enable_sendfile == ENABLE_SENDFILE_OFF)
+ ? 0 : APR_SENDFILE_ENABLED);
#endif
rc = apr_file_open(&dobj->fd, dobj->datafile, flags, 0, r->pool);
if (rc != APR_SUCCESS) {
@@ -907,7 +916,9 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info
if (r->headers_out) {
apr_table_t *headers_out;
- headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out,
+ headers_out = apr_table_overlay(r->pool, r->headers_out,
+ r->err_headers_out);
+ headers_out = ap_cache_cacheable_hdrs_out(r->pool, headers_out,
r->server);
if (!apr_table_get(headers_out, "Content-Type")
@@ -916,8 +927,12 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info
ap_make_content_type(r, r->content_type));
}
- headers_out = apr_table_overlay(r->pool, headers_out,
- r->err_headers_out);
+ if (!apr_table_get(headers_out, "Content-Encoding")
+ && r->content_encoding) {
+ apr_table_setn(headers_out, "Content-Encoding",
+ r->content_encoding);
+ }
+
rv = store_table(dobj->hfd, headers_out);
if (rv != APR_SUCCESS) {
return rv;
diff --git a/modules/cache/mod_mem_cache.c b/modules/cache/mod_mem_cache.c
index 65f35327..7bdaeac9 100644
--- a/modules/cache/mod_mem_cache.c
+++ b/modules/cache/mod_mem_cache.c
@@ -604,7 +604,9 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info
mobj->req_hdrs = deep_table_copy(mobj->pool, r->headers_in);
/* Precompute how much storage we need to hold the headers */
- headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out,
+ headers_out = apr_table_overlay(r->pool, r->headers_out,
+ r->err_headers_out);
+ headers_out = ap_cache_cacheable_hdrs_out(r->pool, headers_out,
r->server);
/* If not set in headers_out, set Content-Type */
@@ -614,7 +616,12 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info
ap_make_content_type(r, r->content_type));
}
- headers_out = apr_table_overlay(r->pool, headers_out, r->err_headers_out);
+ if (!apr_table_get(headers_out, "Content-Encoding")
+ && r->content_encoding) {
+ apr_table_setn(headers_out, "Content-Encoding",
+ r->content_encoding);
+ }
+
mobj->header_out = deep_table_copy(mobj->pool, headers_out);
/* Init the info struct */