* from another request, then this filter will be added before those other
* filters.
*
- * To re-iterate that last comment. This function is building a LIFO
+ * To re-iterate that last comment. This function is building a FIFO
* list of filters. Take note of that when adding your filter to the chain.
*/
/**
- * Add a filter to the current request. Filters are added in a LIFO manner.
- * The first filter added will be the last filter called.
+ * Add a filter to the current request. Filters are added in a FIFO manner.
+ * The first filter added will be the first filter called.
* @param name The name of the filter to add
* @param ctx Any filter specific data to associate with the filter
* @param r The request to add this filter for.
- * @param curr The filter to add this filter after. This is incredibly useful
- * if you are adding a filter while executing another filter. The
- * new filter should be added immediately after the current filter.
- * By passing the current filter into ap_add_filter, this is
- * accomplished easily.
- * @deffunc void ap_add_filter(const char *name, void *ctx, request_rec *r, ap_filter_t *curr)
+ * @deffunc void ap_add_filter(const char *name, void *ctx, request_rec *r)
*/
-API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r,
- ap_filter_t *curr);
+API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r);
/* The next two filters are for abstraction purposes only. They could be
* done away with, but that would require that we break modules if we ever
static void core_register_filter(request_rec *r)
{
- ap_add_filter("CORE", NULL, r, NULL);
+ ap_add_filter("CORE", NULL, r);
}
static void register_hooks(void)
* request-processing time.
*/
ap_hook_insert_filter(core_register_filter, NULL, NULL, AP_HOOK_MIDDLE);
- ap_register_filter("CORE", core_filter, AP_FTYPE_CONNECTION);
+ ap_register_filter("CORE", core_filter, AP_FTYPE_CONNECTION + 1);
ap_register_filter("CHUNK", chunk_filter, AP_FTYPE_CONNECTION);
}
if (r->chunked) {
apr_table_mergen(r->headers_out, "Transfer-Encoding", "chunked");
apr_table_unset(r->headers_out, "Content-Length");
- ap_add_filter("CHUNK", NULL, r, NULL);
+ ap_add_filter("CHUNK", NULL, r);
}
if (r->byterange > 1)
apr_register_cleanup(FILTER_POOL, NULL, filter_cleanup, apr_null_cleanup);
}
-API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r,
- ap_filter_t *curr)
+API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r)
{
ap_filter_rec_t *frec = registered_filters;
f->ftype = frec->ftype;
f->r = r;
- if (curr) {
- f->next = curr->next;
- curr->next = f;
- }
- else {
+ if (INSERT_BEFORE(f, r->filters)) {
f->next = r->filters;
r->filters = f;
}
+ else {
+ ap_filter_t *fscan = r->filters;
+ while (!INSERT_BEFORE(f, fscan->next))
+ fscan = fscan->next;
+ f->next = fscan->next;
+ fscan->next = f;
+ }
+
break;
}
}