summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Stoddard <stoddard@apache.org>2002-03-27 23:42:16 +0100
committerBill Stoddard <stoddard@apache.org>2002-03-27 23:42:16 +0100
commit7da34b011deafd938e7e696b44aeef31afd316cc (patch)
tree06b974d7140acb82800b46217be7a110a8f52190
parentadd license (diff)
downloadapache2-7da34b011deafd938e7e696b44aeef31afd316cc.tar.xz
apache2-7da34b011deafd938e7e696b44aeef31afd316cc.zip
Add a new parameter to the quick_handler hook to instruct
quick handlers to optionally do a lookup rather than actually serve content. This is the first of several changes required fix several problems with how quick handlers work with subrequests. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94240 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES5
-rw-r--r--include/ap_mmn.h3
-rw-r--r--include/http_config.h6
-rw-r--r--modules/experimental/mod_cache.c22
-rw-r--r--modules/http/http_request.c26
-rw-r--r--server/config.c4
-rw-r--r--server/request.c56
7 files changed, 71 insertions, 51 deletions
diff --git a/CHANGES b/CHANGES
index 500692fd7f..1a1b3fe82b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,9 @@
Changes with Apache 2.0.35
+ *) Add a new parameter to the quick_handler hook to instruct
+ quick handlers to optionally do a lookup rather than actually
+ serve content. This is the first of several changes required fix
+ several problems with how quick handlers work with subrequests.
+ [Bill Stoddard]
*) worker MPM: Get MaxRequestsPerChild to work again. [Jeff Trawick]
diff --git a/include/ap_mmn.h b/include/ap_mmn.h
index 75f5aff638..b3344869e2 100644
--- a/include/ap_mmn.h
+++ b/include/ap_mmn.h
@@ -101,12 +101,13 @@
* 20020306 (2.0.34-dev) bump for filter type renames.
* 20020318 (2.0.34-dev) mod_dav's API for REPORT generation changed
* 20020319 (2.0.34-dev) M_INVALID changed, plus new M_* methods for RFC 3253
+ * 20020327 (2.0.35-dev) Add parameter to quick_handler hook
*/
#define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */
#ifndef MODULE_MAGIC_NUMBER_MAJOR
-#define MODULE_MAGIC_NUMBER_MAJOR 20020319
+#define MODULE_MAGIC_NUMBER_MAJOR 20020327
#endif
#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */
#define MODULE_MAGIC_NUMBER MODULE_MAGIC_NUMBER_MAJOR /* backward compat */
diff --git a/include/http_config.h b/include/http_config.h
index 65db484a4f..1b6fd1ae58 100644
--- a/include/http_config.h
+++ b/include/http_config.h
@@ -1013,9 +1013,13 @@ AP_DECLARE_HOOK(int,handler,(request_rec *r))
* is run before any other requests hooks are called (location_walk,
* directory_walk, access checking, et. al.). This hook was added
* to provide a quick way to serve content from a URI keyed cache.
+ *
* @param r The request_rec
+ * @param lookup_uri Controls whether the caller actually wants content or not.
+ * lookup is set when the quick_handler is called out of
+ * ap_sub_req_lookup_uri()
*/
-AP_DECLARE_HOOK(int,quick_handler,(request_rec *r))
+AP_DECLARE_HOOK(int,quick_handler,(request_rec *r, int lookup_uri))
/**
* Retrieve the optional functions for each module.
diff --git a/modules/experimental/mod_cache.c b/modules/experimental/mod_cache.c
index 280341176f..d05fca04dc 100644
--- a/modules/experimental/mod_cache.c
+++ b/modules/experimental/mod_cache.c
@@ -82,7 +82,7 @@ APR_OPTIONAL_FN_TYPE(ap_cache_generate_key) *cache_generate_key;
* oh well.
*/
-static int cache_url_handler(request_rec *r)
+static int cache_url_handler(request_rec *r, int lookup)
{
apr_status_t rv;
const char *cc_in, *pragma, *auth;
@@ -189,12 +189,13 @@ static int cache_url_handler(request_rec *r)
rv = cache_select_url(r, cache->types, url);
if (DECLINED == rv) {
- /* no existing cache file */
- ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
- "cache: no cache - add cache_in filter and DECLINE");
- /* add cache_in filter to cache this request */
- ap_add_output_filter("CACHE_IN", NULL, r, r->connection);
- /* return DECLINED */
+ if (!lookup) {
+ /* no existing cache file */
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
+ "cache: no cache - add cache_in filter and DECLINE");
+ /* add cache_in filter to cache this request */
+ ap_add_output_filter("CACHE_IN", NULL, r, r->connection);
+ }
return DECLINED;
}
else if (OK == rv) {
@@ -203,6 +204,9 @@ static int cache_url_handler(request_rec *r)
apr_bucket_brigade *out;
/* fresh data available */
+ if (lookup) {
+ return OK;
+ }
ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
"cache: fresh cache - add cache_out filter and "
"handle request");
@@ -235,6 +239,10 @@ static int cache_url_handler(request_rec *r)
}
else {
/* stale data available */
+ if (lookup) {
+ return DECLINED;
+ }
+
ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
"cache: stale cache - test conditional");
/* if conditional request */
diff --git a/modules/http/http_request.c b/modules/http/http_request.c
index 50a7c68b27..36b1ceed12 100644
--- a/modules/http/http_request.c
+++ b/modules/http/http_request.c
@@ -239,11 +239,29 @@ void ap_process_request(request_rec *r)
{
int access_status;
- access_status = ap_process_request_internal(r);
- if (access_status == OK) {
- access_status = ap_invoke_handler(r);
+ /* Give quick handlers a shot at serving the request on the fast
+ * path, bypassing all of the other Apache hooks.
+ *
+ * This hook was added to enable serving files out of a URI keyed
+ * content cache ( e.g., Mike Abbott's Quick Shortcut Cache,
+ * described here: http://oss.sgi.com/projects/apache/mod_qsc.html )
+ *
+ * It may have other uses as well, such as routing requests directly to
+ * content handlers that have the ability to grok HTTP and do their
+ * own access checking, etc (e.g. servlet engines).
+ *
+ * Use this hook with extreme care and only if you know what you are
+ * doing.
+ */
+ access_status = ap_run_quick_handler(r, 0); /* Not a look-up request */
+ if (access_status == DECLINED) {
+ access_status = ap_process_request_internal(r);
+ if (access_status == OK) {
+ access_status = ap_invoke_handler(r);
+ }
}
- else if (access_status == DONE) {
+
+ if (access_status == DONE) {
/* e.g., something not in storage like TRACE */
access_status = OK;
}
diff --git a/server/config.c b/server/config.c
index 037f88b3a9..0c89758dc6 100644
--- a/server/config.c
+++ b/server/config.c
@@ -193,8 +193,8 @@ AP_IMPLEMENT_HOOK_VOID(child_init,
AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r),
(r), DECLINED)
-AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r),
- (r), DECLINED)
+AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
+ (r, lookup), DECLINED)
AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
diff --git a/server/request.c b/server/request.c
index ac3748612d..42c8fe046b 100644
--- a/server/request.c
+++ b/server/request.c
@@ -145,36 +145,6 @@ AP_DECLARE(int) ap_process_request_internal(request_rec *r)
int file_req = (r->main && r->filename);
int access_status;
- /* Give quick handlers a shot at serving the request on the fast
- * path, bypassing all of the other Apache hooks. Bypass the call
- * for dirent subrequests (any other cases to bypass?)
- *
- * This hook was added to enable serving files out of a URI keyed
- * content cache ( e.g., Mike Abbott's Quick Shortcut Cache,
- * described here: http://oss.sgi.com/projects/apache/mod_qsc.html )
- *
- * It may have other uses as well, such as routing requests directly to
- * content handlers that have the ability to grok HTTP and do their
- * own access checking, etc (e.g. servlet engines).
- *
- * Use this hook with extreme care and only if you know what you are
- * doing. This hook is available to (non dirent) subrequests.
- */
- if (!(r->main && r->filename && r->finfo.filetype)) {
- /* TODO?: Add a field to the request_rec explicitly identifying
- * the type of subrequest?
- */
- access_status = ap_run_quick_handler(r);
- if (access_status != DECLINED) {
- if (access_status == OK) {
- return DONE;
- }
- else {
- return access_status;
- }
- }
- }
-
/* Ignore embedded %2F's in path for proxy requests */
if (!r->proxyreq && r->parsed_uri.path) {
access_status = ap_unescape_url(r->parsed_uri.path);
@@ -1657,10 +1627,17 @@ AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
udir = ap_escape_uri(rnew->pool, udir); /* re-escape it */
ap_parse_uri(rnew, ap_make_full_path(rnew->pool, udir, new_file));
}
+ /* lookup_uri
+ * If the content can be served by the quick_handler, we can
+ * safely bypass request_internal processing.
+ */
+ res = ap_run_quick_handler(rnew, 1);
- if ((res = ap_process_request_internal(rnew))) {
- rnew->status = res;
- }
+ if (res != OK) {
+ if ((res = ap_process_request_internal(rnew))) {
+ rnew->status = res;
+ }
+ }
return rnew;
}
@@ -1879,9 +1856,16 @@ AP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
AP_DECLARE(int) ap_run_sub_req(request_rec *r)
{
- int retval;
-
- retval = ap_invoke_handler(r);
+ int retval = DECLINED;
+ /* Run the quick handler if the subrequest is not a dirent or file
+ * subrequest
+ */
+ if (!(r->filename && r->finfo.filetype)) {
+ retval = ap_run_quick_handler(r, 0);
+ }
+ if (retval != OK) {
+ retval = ap_invoke_handler(r);
+ }
ap_finalize_sub_req_protocol(r);
return retval;
}