]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
* mod_disk_cache, mod_mem_cache: don't cache incomplete responses,
authorJim Jagielski <jim@apache.org>
Fri, 18 Dec 2009 14:13:05 +0000 (14:13 +0000)
committerJim Jagielski <jim@apache.org>
Fri, 18 Dec 2009 14:13:05 +0000 (14:13 +0000)
      per RFC 2616, 13.8.
          PR 15866
              Trunk Patch: http://svn.apache.org/viewvc?rev=818492&view=rev
                               http://svn.apache.org/viewvc?rev=821763&view=rev
                                   2.2.x Patch: http://people.apache.org/~poirier/PR15866-22x.patch
                                       +1: poirier, rpluem, rjung, jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@892260 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
modules/cache/mod_disk_cache.c
modules/cache/mod_mem_cache.c

diff --git a/CHANGES b/CHANGES
index 79f44ad20283c4dc1921a9ef9266d81093a90609..d79c54eb35ed1b41d2e4db9cd775536af207884f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -27,6 +27,9 @@ Changes with Apache 2.2.15
      for the default values of 1024 for LdapCacheEntries/LdapOpCacheEntries.
      PR 46749. [Stefan Fritsch]
 
+  *) mod_disk_cache, mod_mem_cache: don't cache incomplete responses,
+     per RFC 2616, 13.8.  PR15866.  [Dan Poirier]
+
   *) mod_rewrite: Make sure that a hostname:port isn't fully qualified if
      the request is a CONNECT request. PR 47928
      [Bill Zajac <billz consultla.com>]
diff --git a/STATUS b/STATUS
index dd4a80114f6d057da35701e6180c65809488b3ec..19bc96e05ce9ff2b53c5a59ca6c1b3c2b91a98e6 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -87,14 +87,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  * mod_disk_cache, mod_mem_cache: don't cache incomplete responses,
-    per RFC 2616, 13.8.
-    PR 15866
-    Trunk Patch: http://svn.apache.org/viewvc?rev=818492&view=rev
-                 http://svn.apache.org/viewvc?rev=821763&view=rev
-    2.2.x Patch: http://people.apache.org/~poirier/PR15866-22x.patch
-    +1: poirier, rpluem, rjung, jim
-
   * mod_filter: dispatch correctly where dispatch string doesn't exist
     PR 48054
     Trunk patch: n/a (trunk upgraded to use ap_expr for condition testing)
index 70a804b8955d47b75a7c7bac2d1626fbf3597f5f..7c50cd05cbc32617b0e88dcb87e34d279dced1d2 100644 (file)
@@ -1041,6 +1041,8 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r,
      * sanity checks.
      */
     if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
+        const char *cl_header = apr_table_get(r->headers_out, "Content-Length");
+
         if (r->connection->aborted || r->no_cache) {
             ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
                          "disk_cache: Discarding body for URL %s "
@@ -1059,6 +1061,17 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r,
             file_cache_errorcleanup(dobj, r);
             return APR_EGENERAL;
         }
+        if (cl_header) {
+            apr_size_t cl = apr_atoi64(cl_header);
+            if ((errno == 0) && (dobj->file_size != cl)) {
+                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+                             "disk_cache: URL %s didn't receive complete response, not caching",
+                             h->cache_obj->key);
+                /* Remove the intermediate cache file and return non-APR_SUCCESS */
+                file_cache_errorcleanup(dobj, r);
+                return APR_EGENERAL;
+            }
+        }
 
         /* All checks were fine. Move tempfile to final destination */
         /* Link to the perm file, and close the descriptor */
index 48bd785c50a5e4a6048f690f1a42b15b713890ec..0edf0ffa424e45bf680479bd91dd8ad82e75e69e 100644 (file)
@@ -745,6 +745,16 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r, apr_bucket_bri
         apr_size_t len;
 
         if (APR_BUCKET_IS_EOS(e)) {
+            const char *cl_header = apr_table_get(r->headers_out, "Content-Length");
+            if (cl_header) {
+                apr_size_t cl = apr_atoi64(cl_header);
+                if ((errno == 0) && (obj->count != cl)) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+                                 "mem_cache: URL %s didn't receive complete response, not caching",
+                                 h->cache_obj->key);
+                    return APR_EGENERAL;
+                }
+            }
             if (mobj->m_len > obj->count) {
                 /* Caching a streamed response. Reallocate a buffer of the
                  * correct size and copy the streamed response into that