]> granicus.if.org Git - apache/commitdiff
Add a new parameter to the quick_handler hook to instruct
authorBill Stoddard <stoddard@apache.org>
Wed, 27 Mar 2002 22:42:16 +0000 (22:42 +0000)
committerBill Stoddard <stoddard@apache.org>
Wed, 27 Mar 2002 22:42:16 +0000 (22:42 +0000)
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

CHANGES
include/ap_mmn.h
include/http_config.h
modules/experimental/mod_cache.c
modules/http/http_request.c
server/config.c
server/request.c

diff --git a/CHANGES b/CHANGES
index 500692fd7f9bdef66f520b651d280c5dbdd93e22..1a1b3fe82bc61fcebed3bccca64fbd28aa57b960 100644 (file)
--- 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]
 
index 75f5aff63894ad7f4fb3e24488aad98d7594fd3f..b3344869e2bd843355914a510008058b0bdede85 100644 (file)
  * 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 */
index 65db484a4ff227f855e155ffda34e834d9e4a53d..1b6fd1ae58f7dba3cf7530dd46e326f96256423b 100644 (file)
@@ -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.
index 280341176f5166f94079580bfb62d88634d7ec0c..d05fca04dcd7db62878b64d063acbd82dd6eca22 100644 (file)
@@ -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 */
index 50a7c68b27391aa1b6290cca1ec4a376dfb1f7f9..36b1ceed125fab0f1e6780eea962258cf30b21e0 100644 (file)
@@ -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;
     }
index 037f88b3a9fb9b8b08033826a45c8457945792c0..0c89758dc6dc02fad58aecf9c63bd574d1f10745 100644 (file)
@@ -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), ())
 
index ac3748612d9771b53ef96b74f7029d862ab2eecc..42c8fe046b0b224e7a83662e1c71b1bdaff1627a 100644 (file)
@@ -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;
 }