]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Fixes and cleanups for mod_cache;
authorColm MacCarthaigh <colm@apache.org>
Mon, 26 Sep 2005 09:21:45 +0000 (09:21 +0000)
committerColm MacCarthaigh <colm@apache.org>
Mon, 26 Sep 2005 09:21:45 +0000 (09:21 +0000)
    * Add r->uri to the debug messages in the quick handler; makes debugging
      easier.

    * Always reset headers_in for lookup's, some modules make subrequests
      and then rewrite the url. Having a conditional request at this point
      is not what they expect (nor reasonable for them to handle).

    * Don't store a per-request config on lookups; for the same reason.

    * Return DECLINED when in lookup mode and ap_meets_conditions() indicated
      we have the content but don't know if it's fresh or not. We have no idea
      whether the backend will have a 404, a 304 or any other kind of a
      response - so we have to assume we cannot handle the request.

    * remove the unused "url" argument from the cache_create_entity() function

    * Whitespace/comment fixups in mod_cache.h

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@291588 13f79535-47bb-0310-9956-ffa450edef68

modules/cache/cache_storage.c
modules/cache/mod_cache.c
modules/cache/mod_cache.h

index 46387c27dc90fa2e243b9f86c88f4955c61ed6a0..8c83149306170d6105d13ca284b57dd9ce8541e3 100644 (file)
@@ -66,7 +66,7 @@ int cache_remove_url(cache_request_rec *cache, apr_pool_t *p)
  * decide whether or not it wants to cache this particular entity.
  * If the size is unknown, a size of -1 should be set.
  */
-int cache_create_entity(request_rec *r, char *url, apr_off_t size)
+int cache_create_entity(request_rec *r, apr_off_t size)
 {
     cache_provider_list *list;
     cache_handle_t *h = apr_pcalloc(r->pool, sizeof(cache_handle_t));
index 0bd4d23663e3e1f1d157aae99dac1b8217c9686e..17e046dbee2632e2abba60fab0b501881790d458 100644 (file)
@@ -110,14 +110,15 @@ static int cache_url_handler(request_rec *r, int lookup)
         if (rv == DECLINED) {
             if (!lookup) {
                 ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r->server,
-                  "Adding CACHE_SAVE filter.");
+                  "Adding CACHE_SAVE filter for %s", r->uri);
 
                 /* add cache_save filter to cache this request */
                 ap_add_output_filter_handle(cache_save_filter_handle, NULL, r,
                                             r->connection);
 
                 ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r->server,
-                             "Adding CACHE_REMOVE_URL filter.");
+                             "Adding CACHE_REMOVE_URL filter for %s", 
+                             r->uri);
 
                 /* Add cache_remove_url filter to this request to remove a
                  * stale cache entry if needed. Also put the current cache
@@ -129,11 +130,17 @@ static int cache_url_handler(request_rec *r, int lookup)
                     ap_add_output_filter_handle(cache_remove_url_filter_handle, 
                                                 cache, r, r->connection);
             }
-            else if (cache->stale_headers) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r->server,
-                  "Restoring request headers.");
-
-                r->headers_in = cache->stale_headers;
+            else {
+                if (cache->stale_headers) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, 
+                                 r->server, "Restoring request headers for %s", 
+                                 r->uri);
+
+                    r->headers_in = cache->stale_headers;
+                }
+                
+                /* Delete our per-request configuration. */
+                ap_set_module_config(r->request_config, &cache_module, NULL);
             }
         }
         else {
@@ -144,9 +151,29 @@ static int cache_url_handler(request_rec *r, int lookup)
         }
         return DECLINED;
     }
+    /* if we are a lookup, we are exiting soon one way or another; Restore
+     * the headers. */
+    if (lookup) {
+        if (cache->stale_headers) {
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r->server, 
+                         "Restoring request headers.");
+            r->headers_in = cache->stale_headers;
+        }
+
+        /* Delete our per-request configuration. */
+        ap_set_module_config(r->request_config, &cache_module, NULL);
+    }
 
     rv = ap_meets_conditions(r);
     if (rv != OK) {
+        /* If we are a lookup, we have to return DECLINED as we have no
+         * way of knowing if we will be able to serve the content. 
+         */
+        if (lookup) {
+            return DECLINED;
+        }
+
         /* Return cached status. */
         return rv;
     }
@@ -245,7 +272,6 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
     request_rec *r = f->r;
     cache_request_rec *cache;
     cache_server_conf *conf;
-    char *url = r->unparsed_uri;
     const char *cc_out, *cl;
     const char *exps, *lastmods, *dates, *etag;
     apr_time_t exp, date, lastmod, now;
@@ -445,7 +471,8 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
 
     if (reason) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                     "cache: %s not cached. Reason: %s", url, reason);
+                     "cache: %s not cached. Reason: %s", r->unparsed_uri, 
+                     reason);
 
         /* remove this filter from the chain */
         ap_remove_output_filter(f);
@@ -531,7 +558,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
 
     /* no cache handle, create a new entity */
     if (!cache->handle) {
-        rv = cache_create_entity(r, url, size);
+        rv = cache_create_entity(r, size);
         info = apr_pcalloc(r->pool, sizeof(cache_info));
         /* We only set info->status upon the initial creation. */
         info->status = r->status;
@@ -544,7 +571,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
     }
 
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                 "cache: Caching url: %s", url);
+                 "cache: Caching url: %s", r->unparsed_uri);
 
     /* We are actually caching this response. So it does not
      * make sense to remove this entity any more.
index 87dbd0431165c3ba8498cd9f9e048cecf3427f3f..0e16e19580b2ca7bd1f9310af1309391abf083c3 100644 (file)
@@ -216,15 +216,15 @@ struct cache_provider_list {
 
 /* per request cache information */
 typedef struct {
-    cache_provider_list *providers;         /* possible cache providers */
-    const cache_provider *provider;         /* current cache provider */
-    const char *provider_name;              /* current cache provider name */
-    int fresh;                         /* is the entitey fresh? */
-    cache_handle_t *handle;            /* current cache handle */
-    cache_handle_t *stale_handle;      /* stale cache handle */
-    apr_table_t *stale_headers;                /* original request headers. */
-    int in_checked;                    /* CACHE_SAVE must cache the entity */
-    int block_response;                        /* CACHE_SAVE must block response. */
+    cache_provider_list *providers;     /* possible cache providers */
+    const cache_provider *provider;     /* current cache provider */
+    const char *provider_name;          /* current cache provider name */
+    int fresh;                          /* is the entitey fresh? */
+    cache_handle_t *handle;             /* current cache handle */
+    cache_handle_t *stale_handle;       /* stale cache handle */
+    apr_table_t *stale_headers;         /* original request headers. */
+    int in_checked;                     /* CACHE_SAVE must cache the entity */
+    int block_response;                 /* CACHE_SAVE must block response. */
     apr_bucket_brigade *saved_brigade;  /* copy of partial response */
     apr_off_t saved_size;               /* length of saved_brigade */
     apr_time_t exp;                     /* expiration */
@@ -278,7 +278,7 @@ CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool,
  * cache_storage.c
  */
 int cache_remove_url(cache_request_rec *cache, apr_pool_t *p);
-int cache_create_entity(request_rec *r, char *url, apr_off_t size);
+int cache_create_entity(request_rec *r, apr_off_t size);
 int cache_select(request_rec *r);
 apr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
 /**