Index: mod_disk_cache.c
===================================================================
--- mod_disk_cache.c	(revision 470455)
+++ mod_disk_cache.c	(working copy)
@@ -1457,6 +1457,7 @@
 static apr_status_t store_disk_header(disk_cache_object_t *dobj,
                                        request_rec *r, cache_info *info)
 {
+	if ( dobj->initial_size < 0) return APR_SUCCESS; //do not store incorrect size. GG
     disk_cache_format_t format = DISK_FORMAT_VERSION;
     struct iovec iov[3];
     int niov;
@@ -1472,22 +1473,25 @@
     disk_info.status = info->status;
     disk_info.file_size = dobj->initial_size;
 
-    niov = 0;
-    iov[niov].iov_base = (void*)&format;
-    iov[niov++].iov_len = sizeof(format);
-    iov[niov].iov_base = (void*)&disk_info;
-    iov[niov++].iov_len = sizeof(disk_cache_info_t);
+		
+	niov = 0;
+	iov[niov].iov_base = (void*)&format;
+	iov[niov++].iov_len = sizeof(format);
+	iov[niov].iov_base = (void*)&disk_info;
+	iov[niov++].iov_len = sizeof(disk_cache_info_t);
 
-    disk_info.name_len = strlen(dobj->name);
-    iov[niov].iov_base = (void*)dobj->name;
-    iov[niov++].iov_len = disk_info.name_len;
+	disk_info.name_len = strlen(dobj->name);
+	iov[niov].iov_base = (void*)dobj->name;
+	iov[niov++].iov_len = disk_info.name_len;
 
-    rv = apr_file_writev(dobj->hfd, (const struct iovec *) &iov, niov, &amt);
-    if (rv != APR_SUCCESS) {
-        file_cache_errorcleanup(dobj, r);
-        return rv;
-    }
+	rv = apr_file_writev(dobj->hfd, (const struct iovec *) &iov, niov, &amt);
+	if (rv != APR_SUCCESS) {
+		file_cache_errorcleanup(dobj, r);
+		return rv;
+	}
+	
 
+
     if (r->headers_out) {
         apr_table_t *headers_out;
 
@@ -1536,7 +1540,6 @@
     int flags=0, rewriting;
     disk_cache_object_t *dobj = (disk_cache_object_t*) h->cache_obj->vobj;
 
-
     /* This is flaky... we need to manage the cache_info differently */
     h->cache_obj->info = *info;
 
@@ -1845,64 +1848,73 @@
 
         apr_brigade_cleanup(dobj->tmpbb);
 
-    }
 
-    
-    /* Drop out here if this wasn't the end */
-    if (!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
-        return APR_SUCCESS;
-    }
+		// EOS, so we update the headers. GG
+		if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
+		
+			ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+						 "disk_cache: Done caching URL %s, len %" APR_OFF_T_FMT,
+						 dobj->name, dobj->file_size);
+		
+			if (APR_SUCCESS != dobj->frv) {
+				ap_log_error(APLOG_MARK, APLOG_ERR, dobj->frv, r->server,
+							 "disk_cache: An error occurred while writing to the "
+							 "network for URL %s.",
+							 h->cache_obj->key);
+			}
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                 "disk_cache: Done caching URL %s, len %" APR_OFF_T_FMT,
-                 dobj->name, dobj->file_size);
+			if (dobj->file_size < conf->minfs) {
+				ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+							 "disk_cache: URL %s failed the size check "
+							 "(%" APR_OFF_T_FMT "<%" APR_OFF_T_FMT ")",
+							 h->cache_obj->key, dobj->file_size, conf->minfs);
+				/* Remove the intermediate cache file and return filter status */
+				file_cache_errorcleanup(dobj, r);
+				return dobj->frv;
+			}
+			if (dobj->initial_size < 0) {
+				/* Update header information now that we know the size */
+				dobj->initial_size = dobj->file_size;
+				dobj->disk_info.file_size = dobj->file_size; //GG added. required?
+				rv = store_headers(h, r, &(h->cache_obj->info));
+				if (rv != APR_SUCCESS) {
+					file_cache_errorcleanup(dobj, r);
+					return dobj->frv;
+				}
+			}
+			else if (dobj->initial_size != dobj->file_size) {
+				ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+							 "disk_cache: URL %s - body size mismatch: suggested %"
+							 APR_OFF_T_FMT "  bodysize %" APR_OFF_T_FMT ")",
+							 dobj->name, dobj->initial_size, dobj->file_size);
+				file_cache_errorcleanup(dobj, r);
+				return dobj->frv;
+			}
+		
+			/* All checks were fine, close output file */
+			rv = apr_file_close(dobj->fd);
+			dobj->fd = NULL;
+			if (rv != APR_SUCCESS) {
+				ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+							 "disk_cache: While trying to close the cache file for "
+							 "URL %s, the close failed", dobj->name);
+				file_cache_errorcleanup(dobj, r);
+				return dobj->frv;
+			}
+		
+			return dobj->frv;
+				
+				
+				
+				
+		}
 
-    if (APR_SUCCESS != dobj->frv) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, dobj->frv, r->server,
-                     "disk_cache: An error occurred while writing to the "
-                     "network for URL %s.",
-                     h->cache_obj->key);
-    }
 
-    if (dobj->file_size < conf->minfs) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                     "disk_cache: URL %s failed the size check "
-                     "(%" APR_OFF_T_FMT "<%" APR_OFF_T_FMT ")",
-                     h->cache_obj->key, dobj->file_size, conf->minfs);
-        /* Remove the intermediate cache file and return filter status */
-        file_cache_errorcleanup(dobj, r);
-        return dobj->frv;
-    }
-    if (dobj->initial_size < 0) {
-        /* Update header information now that we know the size */
-        dobj->initial_size = dobj->file_size;
-        rv = store_headers(h, r, &(h->cache_obj->info));
-        if (rv != APR_SUCCESS) {
-            file_cache_errorcleanup(dobj, r);
-            return dobj->frv;
-        }
-    }
-    else if (dobj->initial_size != dobj->file_size) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                     "disk_cache: URL %s - body size mismatch: suggested %"
-                     APR_OFF_T_FMT "  bodysize %" APR_OFF_T_FMT ")",
-                     dobj->name, dobj->initial_size, dobj->file_size);
-        file_cache_errorcleanup(dobj, r);
-        return dobj->frv;
-    }
 
-    /* All checks were fine, close output file */
-    rv = apr_file_close(dobj->fd);
-    dobj->fd = NULL;
-    if (rv != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                     "disk_cache: While trying to close the cache file for "
-                     "URL %s, the close failed", dobj->name);
-        file_cache_errorcleanup(dobj, r);
-        return dobj->frv;
     }
 
-    return dobj->frv;
+	return APR_SUCCESS;
+
 }
 
 
