The filters which are registered via ns_register_filter
and Ns_RegisterFilter() are run in FIFO order. This
can be inconvenient for a couple of reasons:
1) it places constraints on code layout, which procs
go where, how you name files to force load order etc.
2) because of initialisation order -- C modules
first, private Tcl library second -- it is impossible
to overide a C filter from Tcl.
This patch adds two new filter options:
which can be ORed into the 'when' clause.
when = NS_FILTER_PREAUTH | NS_FILTER_FIRST;
Ns_RegisterFilter(server, method, url, MyFilter,
The filter is added to the head of the filter list
rather than the tail, which is still the default. It
will be run first unless another filter is registered
with the NS_FILTER_FIRST option.
I don't think a more elaborate scheme of numerical
priorities is worth the effort. However, this patch is
fully forwards and backwards compatible, should someone
else decide to impelement such a thing.
This patch adds the corresponding '-first' flag as an
option to the ns_register_filter command. It functions
One of the primary motivations for this patch is to
shortcut filter processing. It's very convenient to
register site-wide filters which do chores such as
session management, authorization etc. Some
directories should not have the overhead, such as
/downloads or /images.
With the 4.1 thread pool feature, you can segregate
these URLs into a pool of their own, but to get the
full benefit you have to register your shortcut filters
via the C API. If you use the Tcl API, then each
thread in the downloads threadpool needs a heavyweight
Tcl interp which it wont otherwise use. Interps are
allocated on demand, so if you don't run any Tcl code,
they never get allocated.
This patch introduces the new command:
ns_register_filter_shortcut when method urlPattern
It registers a preauth, postauth or trace filter
NS_FILTER_FIRST for the given method and URL which
simply returns NS_FILTER_BREAK, therefore preventing
further filter processing.