]> granicus.if.org Git - apache/commitdiff
Maintain info structure in mod_mem_cache. This fixes bug where the content
authorBill Stoddard <stoddard@apache.org>
Tue, 11 Sep 2001 17:41:05 +0000 (17:41 +0000)
committerBill Stoddard <stoddard@apache.org>
Tue, 11 Sep 2001 17:41:05 +0000 (17:41 +0000)
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

modules/experimental/cache_storage.c
modules/experimental/mod_cache.c
modules/experimental/mod_mem_cache.c

index 4c679ee8b9f7c33f578f8b7ba8638f5aa31cd1b4..eaffe85555fab84fcdddbbf3d7603f40c1ca7969 100644 (file)
@@ -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) 
index 3303a4a9093b30ecc146772fdc212b781982a9c4..d3316668c5aaf831d787b98657636ebd529222fb 100644 (file)
@@ -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.
      */
index d524febd9f623b4edfb718433ea96823c626b0f5..ad96d1bcc5c5f1d43ce809d5df585ece6d7de453 100644 (file)
@@ -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;
 }