From: Colm MacCarthaigh Date: Thu, 29 Sep 2005 12:20:54 +0000 (+0000) Subject: Merge r291588, r291672 and r291914 from trunk; make mod_dir and mod_cache X-Git-Tag: 2.1.9~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5418c9a2967b0be9113db9a95cfa0d2fb3fd6b3d;p=thirdparty%2Fapache%2Fhttpd.git Merge r291588, r291672 and r291914 from trunk; make mod_dir and mod_cache play nice together. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@292423 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/cache/cache_storage.c b/modules/cache/cache_storage.c index 5d781602702..9c75db2997b 100644 --- a/modules/cache/cache_storage.c +++ b/modules/cache/cache_storage.c @@ -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)); diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index 0bd4d23663e..17e046dbee2 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -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. diff --git a/modules/cache/mod_cache.h b/modules/cache/mod_cache.h index 744f7cc5b12..8e4bea84998 100644 --- a/modules/cache/mod_cache.h +++ b/modules/cache/mod_cache.h @@ -212,15 +212,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 */ @@ -274,7 +274,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 ); /** diff --git a/modules/mappers/mod_dir.c b/modules/mappers/mod_dir.c index b0bc39a7dd0..c2dd0fb058b 100644 --- a/modules/mappers/mod_dir.c +++ b/modules/mappers/mod_dir.c @@ -182,8 +182,17 @@ static int fixup_dir(request_rec *r) rr = ap_sub_req_lookup_uri(name_ptr, r, NULL); - /* XXX: (filetype == APR_REG) - we can't use a non-file index??? */ - if ( rr->status == HTTP_OK + /* The sub request lookup is very liberal, and the core map_to_storage + * handler will almost always result in HTTP_OK as /foo/index.html + * may be /foo with PATH_INFO="/index.html", or even / with + * PATH_INFO="/foo/index.html". To get around this we insist that the + * the index be a regular filetype. + * + * Another reason is that the core handler also makes the assumption + * that if r->finfo is still NULL by the time it gets called, the + * file does not exist. + */ + if (rr->status == HTTP_OK && ( (rr->handler && !strcmp(rr->handler, "proxy-server")) || rr->finfo.filetype == APR_REG)) { ap_internal_fast_redirect(rr, r); diff --git a/server/request.c b/server/request.c index c26c8612a2a..b8ca6a43583 100644 --- a/server/request.c +++ b/server/request.c @@ -1608,10 +1608,18 @@ AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method, /* lookup_uri * If the content can be served by the quick_handler, we can * safely bypass request_internal processing. + * + * If next_filter is NULL we are expecting to be + * internal_fast_redirect'ed to the subrequest, or the subrequest will + * never be invoked. We need to make sure that the quickhandler is not + * invoked by any lookups. Since an internal_fast_redirect will always + * occur too late for the quickhandler to handle the request. */ - res = ap_run_quick_handler(rnew, 1); + if (next_filter) { + res = ap_run_quick_handler(rnew, 1); + } - if (res != OK) { + if (next_filter == NULL || res != OK) { if ((res = ap_process_request_internal(rnew))) { rnew->status = res; }