--- mod_disk_cache.c.orig Mon Feb 9 15:53:16 2004 +++ mod_disk_cache.c Wed Apr 7 10:24:19 2004 @@ -143,11 +143,11 @@ * perhaps we need to create the directory tree where we are * about to write the new file. */ - rv = apr_file_remove(dobj->datafile, r->pool); +/* rv = apr_file_remove(dobj->datafile, r->pool); if (rv != APR_SUCCESS) { mkdir_structure(conf, dobj->datafile, r->pool); } - +*/ /* * This assumes that the tempfile is on the same file system * as the cache_root. If not, then we need a file copy/move @@ -472,7 +472,8 @@ return rv; } - r->status = atoi(urlbuff); /* Save status line into request rec */ +/* r->status = atoi(urlbuff); */ /* Save status line into request rec */ + r->status == 200; /* Read and ignore the status line (This request might result in a * 304, so we don't necessarily want to retransmit a 200 from the cache.) @@ -526,7 +527,6 @@ disk_cache_object_t *dobj = (disk_cache_object_t*) h->cache_obj->vobj; apr_file_t *hfd = dobj->hfd; - if (!hfd) { if (!dobj->hdrsfile) { dobj->hdrsfile = header_file(r->pool, conf->dirlevels, @@ -562,6 +562,7 @@ int i; apr_table_t* headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out); apr_table_entry_t *elts = (apr_table_entry_t *) apr_table_elts(headers_out)->elts; + for (i = 0; i < apr_table_elts(headers_out)->nelts; ++i) { if (elts[i].key != NULL) { buf = apr_pstrcat(r->pool, elts[i].key, ": ", elts[i].val, CRLF, NULL); @@ -569,16 +570,26 @@ apr_file_write(hfd, buf, &amt); } } - buf = apr_pstrcat(r->pool, CRLF, NULL); - amt = strlen(buf); - apr_file_write(hfd, buf, &amt); - + /* This case only occurs when the content is generated locally */ if (!apr_table_get(r->headers_out, "Content-Type") && r->content_type) { - apr_table_setn(r->headers_out, "Content-Type", +/* apr_table_setn(r->headers_out, "Content-Type", ap_make_content_type(r, r->content_type)); +*/ + buf = apr_pstrcat(r->pool,"Content-Type: ", ap_make_content_type(r, r->content_type), CRLF, NULL); + amt = strlen(buf); + apr_file_write(hfd, buf, &amt); + buf = apr_pstrcat(r->pool, CRLF, NULL); + amt = strlen(buf); + apr_file_write(hfd, buf, &amt); } + else { + buf = apr_pstrcat(r->pool, CRLF, NULL); + amt = strlen(buf); + apr_file_write(hfd, buf, &amt); + } } + sprintf(statusbuf,"%d", r->status); buf = apr_pstrcat(r->pool, statusbuf, CRLF, NULL); amt = strlen(buf); @@ -612,16 +623,13 @@ amt = strlen(buf); apr_file_write(hfd, buf, &amt); } - apr_file_close(hfd); /* flush and close */ - } - else { - /* XXX log message */ - } + apr_file_close(hfd); /* flush and close */ ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, "disk_cache: Caching headers for URL %s", dobj->name); return APR_SUCCESS; } + static apr_status_t write_body(cache_handle_t *h, request_rec *r, apr_bucket_brigade *b) { apr_bucket *e;