Run filter "init" functions exactly once per request. No longer run init functions for connection filters (doing an "init" once per handler invocation makes no sense for a connection filter). No longer b) multiple times per filter 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 Index: include/util_filter.h =================================================================== --- include/util_filter.h (revision 952827) +++ include/util_filter.h (working copy) @@ -217,10 +217,13 @@ /** 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: server/config.c =================================================================== --- server/config.c (revision 952827) +++ server/config.c (working copy) @@ -312,10 +312,14 @@ 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 @@ * 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; }