]> granicus.if.org Git - apache/commitdiff
Run filter "init" functions exactly once per request. No longer run
authorJoe Orton <jorton@apache.org>
Thu, 10 Jun 2010 12:52:49 +0000 (12:52 +0000)
committerJoe Orton <jorton@apache.org>
Thu, 10 Jun 2010 12:52:49 +0000 (12:52 +0000)
init functions for connection filters (doing an "init" once per
handler invocation makes no sense for a connection filter).  No longer
run init functions multiple times per request if a subrequest is used.

* include/util_filter.h (ap_filter_rec_t): Clarify use of the init
  function pointer.

* server/config.c (invoke_filter_init): Drop ap_ prefix for private
  function; take a request_rec pointer and only invoke filters with
  matching request.
  (ap_invoke_handler): Adjust accordingly.

PR: 49328
Reviewed by: rpluem

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

CHANGES
include/util_filter.h
server/config.c

diff --git a/CHANGES b/CHANGES
index 8ed9b33242290a7f2a08061baff389ce0b7881aa..a92f2a79e8d65d43091eaa20cfdc921fe7630b4a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -28,6 +28,10 @@ Changes with Apache 2.3.6
      processing is completed, avoiding orphaned callback pointers.
      [Brett Gervasoni <brettg senseofsecurity.com>, Jeff Trawick]
 
+  *) core: Filter init functions are now run strictly once per request
+     before handler invocation.  The init functions are no longer run
+     for connection filters.  PR 49328.  [Joe Orton]
+
   *) core: Adjust the output filter chain correctly in an internal
      redirect from a subrequest, preserving filters from the main
      request as necessary.  PR 17629.  [Joe Orton]
index 8c169de6cd98cd2217903fcb61aee9f7ec1bf339..4467436a15bef6f778545cbefe0556125c93e8ba 100644 (file)
@@ -217,10 +217,13 @@ struct ap_filter_rec_t {
     /** The function to call when this filter is invoked. */
     ap_filter_func filter_func;
 
-    /** The function to call before the handlers are invoked. Notice
-     * that this function is called only for filters participating in
-     * the http protocol. Filters for other protocols are to be
-     * initialized by the protocols themselves.
+    /** The function to call directly before the handlers are invoked
+     * for a request.  The init function is called once directly
+     * before running the handlers for a request or subrequest.  The
+     * init function is never called for a connection filter (with
+     * ftype >= AP_FTYPE_CONNECTION).  Any use of this function for
+     * filters for protocols other than HTTP is specified by the
+     * module supported that protocol.
      */
     ap_init_filter_func filter_init_func;
 
index 085d3395cfb9aa9dbb31707bfee45ea5365c1e7a..0f1660abe9aecdee4b782fcb5336f2015368a09b 100644 (file)
@@ -312,10 +312,14 @@ AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
     return create_empty_config(p);
 }
 
-static int ap_invoke_filter_init(ap_filter_t *filters)
+/* Invoke the filter_init_func for all filters with FILTERS where f->r
+ * matches R.  Restricting to a matching R avoids re-running init
+ * functions for filters configured for r->main where r is a
+ * subrequest.  */
+static int invoke_filter_init(request_rec *r, ap_filter_t *filters)
 {
     while (filters) {
-        if (filters->frec->filter_init_func) {
+        if (filters->frec->filter_init_func && filters->r == r) {
             int result = filters->frec->filter_init_func(filters);
             if (result != OK) {
                 return result;
@@ -354,11 +358,11 @@ AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
      * run their init function to let them do any magic before we could
      * start generating data.
      */
-    result = ap_invoke_filter_init(r->input_filters);
+    result = invoke_filter_init(r, r->input_filters);
     if (result != OK) {
         return result;
     }
-    result = ap_invoke_filter_init(r->output_filters);
+    result = invoke_filter_init(r, r->output_filters);
     if (result != OK) {
         return result;
     }