From: Bill Stoddard Date: Tue, 11 Sep 2001 17:41:05 +0000 (+0000) Subject: Maintain info structure in mod_mem_cache. This fixes bug where the content X-Git-Tag: 2.0.26~269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7fd63fb0641985a52f570917bced7e1055f01315;p=apache Maintain info structure in mod_mem_cache. This fixes bug where the content type was lost when content was put in the cache. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91005 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/experimental/cache_storage.c b/modules/experimental/cache_storage.c index 4c679ee8b9..eaffe85555 100644 --- a/modules/experimental/cache_storage.c +++ b/modules/experimental/cache_storage.c @@ -156,6 +156,7 @@ int cache_select_url(request_rec *r, const char *types, char *url) const char *next = types; const char *type; apr_status_t rv; + cache_info *info; cache_request_rec *cache = (cache_request_rec *) ap_get_module_config(r->request_config, &cache_module); @@ -166,13 +167,14 @@ int cache_select_url(request_rec *r, const char *types, char *url) type = ap_cache_tokstr(r->pool, next, &next); switch ((rv = cache_run_open_entity(cache->handle, type, url))) { case OK: { + info = &(cache->handle->cache_obj->info); /* XXX: * Handle being returned a collection of entities. */ /* Has the cache entry expired? */ #if 0 - if (r->request_time > cache->handle... need to get info out of the cache... info.expire) + if (r->request_time > info->expire) cache->fresh = 0; else #endif @@ -213,11 +215,15 @@ apr_status_t cache_write_entity_body(cache_handle_t *h, apr_bucket_brigade *b) apr_status_t cache_read_entity_headers(cache_handle_t *h, request_rec *r, apr_table_t **headers) { + cache_info *info = &(h->cache_obj->info); + /* Build the header table from info in the info struct */ *headers = apr_table_make(r->pool, 15); h->read_headers(h, r, *headers); + r->content_type = apr_pstrdup(r->pool, info->content_type); + return APR_SUCCESS; } apr_status_t cache_read_entity_body(cache_handle_t *h, apr_bucket_brigade *b) diff --git a/modules/experimental/mod_cache.c b/modules/experimental/mod_cache.c index 3303a4a909..d3316668c5 100644 --- a/modules/experimental/mod_cache.c +++ b/modules/experimental/mod_cache.c @@ -634,6 +634,8 @@ int ap_cache_in_filter(ap_filter_t *f, apr_bucket_brigade *in) } info->expire = exp; + info->content_type = apr_pstrdup(r->pool, r->content_type); + /* * Write away header information to cache. */ diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c index d524febd9f..ad96d1bcc5 100644 --- a/modules/experimental/mod_mem_cache.c +++ b/modules/experimental/mod_mem_cache.c @@ -405,6 +405,7 @@ static int read_body(cache_handle_t *h, apr_bucket_brigade *bb) static int write_headers(cache_handle_t *h, request_rec *r, cache_info *info, apr_table_t *headers) { + cache_object_t *obj = h->cache_obj; mem_cache_object_t *mobj = (mem_cache_object_t*) h->cache_obj->vobj; apr_table_entry_t *elts = (apr_table_entry_t *) headers->a.elts; apr_ssize_t i; @@ -445,7 +446,7 @@ static int write_headers(cache_handle_t *h, request_rec *r, cache_info *info, ap idx+=len; } -#if 0 + /* Init the info struct */ if (info->date) { obj->info.date = info->date; } @@ -456,11 +457,14 @@ static int write_headers(cache_handle_t *h, request_rec *r, cache_info *info, ap obj->info.expire = info->expire; } if (info->content_type) { - obj->info.content_type = (char*) malloc(strlen(info->content_type)); - if (obj->info.content_type) - strcpy((char*) obj->info.content_type, info->content_type); + obj->info.content_type = (char*) malloc(strlen(info->content_type) + 1); + if (!obj->info.content_type) { + /* cleanup the object? */ + return DECLINED; + } + strcpy((char*) obj->info.content_type, info->content_type); } -#endif + return OK; }