You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2016/12/02 11:42:14 UTC
svn commit: r1772331 [2/2] - in /httpd/httpd/branches/2.4.x: ./ docs/manual/
modules/cache/
Modified: httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c?rev=1772331&r1=1772330&r2=1772331&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c (original)
+++ httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c Fri Dec 2 11:42:13 2016
@@ -103,7 +103,7 @@ static int cache_quick_handler(request_r
/*
* Which cache module (if any) should handle this request?
*/
- if (!(providers = cache_get_providers(r, conf, r->parsed_uri))) {
+ if (!(providers = cache_get_providers(r, conf))) {
return DECLINED;
}
@@ -413,7 +413,7 @@ static int cache_handler(request_rec *r)
/*
* Which cache module (if any) should handle this request?
*/
- if (!(providers = cache_get_providers(r, conf, r->parsed_uri))) {
+ if (!(providers = cache_get_providers(r, conf))) {
return DECLINED;
}
@@ -973,12 +973,20 @@ static apr_status_t cache_save_filter(ap
/* Have we received a 304 response without any headers at all? Fall back to
* the original headers in the original cached request.
*/
- if (r->status == HTTP_NOT_MODIFIED && cache->stale_handle && !cc_out
- && !pragma) {
- cc_out = cache_table_getm(r->pool, cache->stale_handle->resp_hdrs,
- "Cache-Control");
- pragma = cache_table_getm(r->pool, cache->stale_handle->resp_hdrs,
- "Pragma");
+ if (r->status == HTTP_NOT_MODIFIED && cache->stale_handle) {
+ if (!cc_out && !pragma) {
+ cc_out = cache_table_getm(r->pool, cache->stale_handle->resp_hdrs,
+ "Cache-Control");
+ pragma = cache_table_getm(r->pool, cache->stale_handle->resp_hdrs,
+ "Pragma");
+ }
+
+ /* 304 does not contain Content-Type and mod_mime regenerates the
+ * Content-Type based on the r->filename. This would lead to original
+ * Content-Type to be lost (overwriten by whatever mod_mime generates).
+ * We preserves the original Content-Type here. */
+ ap_set_content_type(r, apr_table_get(
+ cache->stale_handle->resp_hdrs, "Content-Type"));
}
/* Parse the cache control header */
@@ -1017,6 +1025,8 @@ static apr_status_t cache_save_filter(ap
* 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).
+ *
+ * FIXME: Wrong if cc_out has just an extension we don't know about
*/
}
else {
@@ -1031,9 +1041,12 @@ static apr_status_t cache_save_filter(ap
/* if a broken Expires header is present, don't cache it */
reason = apr_pstrcat(p, "Broken expires header: ", exps, NULL);
}
- else if (!dconf->store_expired && exp != APR_DATE_BAD
+ else if (!control.s_maxage && !control.max_age
+ && !dconf->store_expired && exp != APR_DATE_BAD
&& exp < r->request_time) {
- /* if a Expires header is in the past, don't cache it */
+ /* if a Expires header is in the past, don't cache it
+ * Unless CC: s-maxage or max-age is present
+ */
reason = "Expires header already expired; not cacheable";
}
else if (!dconf->store_expired && (control.must_revalidate
@@ -1177,8 +1190,8 @@ static apr_status_t cache_save_filter(ap
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(02473)
"cache: %s responded with an uncacheable 304, "
- "retrying the request. Reason: %s",
- r->unparsed_uri, reason);
+ "retrying the request %s. Reason: %s",
+ cache->key, r->unparsed_uri, reason);
/* we've got a cache conditional miss! tell anyone who cares */
cache_run_cache_status(cache->handle, r, r->headers_out, AP_CACHE_MISS,
@@ -1212,8 +1225,8 @@ static apr_status_t cache_save_filter(ap
if (reason) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00768)
- "cache: %s not cached. Reason: %s", r->unparsed_uri,
- reason);
+ "cache: %s not cached for request %s. Reason: %s",
+ cache->key, r->unparsed_uri, reason);
/* we've got a cache miss! tell anyone who cares */
cache_run_cache_status(cache->handle, r, r->headers_out, AP_CACHE_MISS,
@@ -1331,7 +1344,8 @@ static apr_status_t cache_save_filter(ap
}
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00769)
- "cache: Caching url: %s", r->unparsed_uri);
+ "cache: Caching url %s for request %s",
+ cache->key, r->unparsed_uri);
/* We are actually caching this response. So it does not
* make sense to remove this entity any more.
@@ -1387,7 +1401,26 @@ static apr_status_t cache_save_filter(ap
"replacing with now");
}
+
+ /* CC has priority over Expires. */
+ if (control.s_maxage || control.max_age) {
+ apr_int64_t x;
+
+ x = control.s_maxage ? control.s_maxage_value : control.max_age_value;
+ x = x * MSEC_ONE_SEC;
+
+ if (x < dconf->minex) {
+ x = dconf->minex;
+ }
+ if (x > dconf->maxex) {
+ x = dconf->maxex;
+ }
+ exp = date + x;
+ }
+
/* if no expiry date then
+ * if Cache-Control: s-maxage
+ * expiry date = date + smaxage
* if Cache-Control: max-age
* expiry date = date + max-age
* else if lastmod
@@ -1395,28 +1428,9 @@ static apr_status_t cache_save_filter(ap
* else
* expire date = date + defaultexpire
*/
- if (exp == APR_DATE_BAD) {
-
- if (control.max_age) {
- apr_int64_t x;
- errno = 0;
- x = control.max_age_value;
- if (errno) {
- x = dconf->defex;
- }
- else {
- x = x * MSEC_ONE_SEC;
- }
- if (x < dconf->minex) {
- x = dconf->minex;
- }
- if (x > dconf->maxex) {
- x = dconf->maxex;
- }
- exp = date + x;
- }
- else if ((lastmod != APR_DATE_BAD) && (lastmod < date)) {
+ if (exp == APR_DATE_BAD) {
+ if ((lastmod != APR_DATE_BAD) && (lastmod < date)) {
/* if lastmod == date then you get 0*conf->factor which results in
* an expiration time of now. This causes some problems with
* freshness calculations, so we choose the else path...
@@ -1558,6 +1572,9 @@ static apr_status_t cache_save_filter(ap
/* let someone else attempt to cache */
cache_remove_lock(conf, cache, r, NULL);
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r, APLOGNO(02971)
+ "cache: serving %s (revalidated)", r->uri);
+
return ap_pass_brigade(f->next, bb);
}
Modified: httpd/httpd/branches/2.4.x/modules/cache/mod_cache_disk.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/cache/mod_cache_disk.c?rev=1772331&r1=1772330&r2=1772331&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/cache/mod_cache_disk.c (original)
+++ httpd/httpd/branches/2.4.x/modules/cache/mod_cache_disk.c Fri Dec 2 11:42:13 2016
@@ -786,7 +786,7 @@ static apr_status_t read_table(cache_han
/* ### What about APR_EOF? */
rv = apr_file_gets(w, MAX_STRING_LEN - 1, file);
if (rv != APR_SUCCESS) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00717)
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00717)
"Premature end of cache headers.");
return rv;
}
@@ -865,6 +865,7 @@ static apr_status_t read_table(cache_han
static apr_status_t recall_headers(cache_handle_t *h, request_rec *r)
{
disk_cache_object_t *dobj = (disk_cache_object_t *) h->cache_obj->vobj;
+ apr_status_t rv;
/* This case should not happen... */
if (!dobj->hdrs.fd) {
@@ -877,8 +878,18 @@ static apr_status_t recall_headers(cache
h->resp_hdrs = apr_table_make(r->pool, 20);
/* Call routine to read the header lines/status line */
- read_table(h, r, h->resp_hdrs, dobj->hdrs.fd);
- read_table(h, r, h->req_hdrs, dobj->hdrs.fd);
+ rv = read_table(h, r, h->resp_hdrs, dobj->hdrs.fd);
+ if (rv != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02987)
+ "Error reading response headers from %s for %s",
+ dobj->hdrs.file, dobj->name);
+ }
+ rv = read_table(h, r, h->req_hdrs, dobj->hdrs.fd);
+ if (rv != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02988)
+ "Error reading request headers from %s for %s",
+ dobj->hdrs.file, dobj->name);
+ }
apr_file_close(dobj->hdrs.fd);
Modified: httpd/httpd/branches/2.4.x/modules/cache/mod_file_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/cache/mod_file_cache.c?rev=1772331&r1=1772330&r2=1772331&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/cache/mod_file_cache.c (original)
+++ httpd/httpd/branches/2.4.x/modules/cache/mod_file_cache.c Fri Dec 2 11:42:13 2016
@@ -312,10 +312,10 @@ static int file_cache_handler(request_re
int errstatus;
int rc = OK;
- /* XXX: not sure if this is right yet
- * see comment in http_core.c:default_handler
+ /* Bail out if r->handler isn't the default value, and doesn't look like a Content-Type
+ * XXX: Even though we made the user explicitly list each path to cache?
*/
- if (ap_strcmp_match(r->handler, "*/*")) {
+ if (ap_strcmp_match(r->handler, "*/*") && !AP_IS_DEFAULT_HANDLER_NAME(r->handler)) {
return DECLINED;
}
Modified: httpd/httpd/branches/2.4.x/modules/cache/mod_socache_memcache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/cache/mod_socache_memcache.c?rev=1772331&r1=1772330&r2=1772331&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/cache/mod_socache_memcache.c (original)
+++ httpd/httpd/branches/2.4.x/modules/cache/mod_socache_memcache.c Fri Dec 2 11:42:13 2016
@@ -214,8 +214,14 @@ static apr_status_t socache_mc_store(ap_
return APR_EINVAL;
}
- /* In APR-util - unclear what 'timeout' is, as it was not implemented */
- rv = apr_memcache_set(ctx->mc, buf, (char*)ucaData, nData, 0, 0);
+ /* memcache needs time in seconds till expiry; fail if this is not
+ * positive *before* casting to unsigned (apr_uint32_t). */
+ expiry -= apr_time_now();
+ if (apr_time_sec(expiry) <= 0) {
+ return APR_EINVAL;
+ }
+ rv = apr_memcache_set(ctx->mc, buf, (char*)ucaData, nData,
+ apr_time_sec(expiry), 0);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(00790)