Forum OpenACS Q&A: How to use ns_register_filter to establish a route to be served by NaviServer

We are currently using the reverse proxy with great success. It handles what we want it to quite nicely. We have come up with a case that we are wondering about though. Is there a way to specify a route that will fall through and be served by NaviServer?

Here is an example:

# I have a route /some-site-loc/* that gets forwarded to a target but, I want two of the sub-routes to be handled else where.
# I want a separate target to handle requests to the sub-route /some-site-loc/names/*; this filter works as expected
# I want NaviServer to handle the sub-route /some-site-loc/ns-special/*; can this be done?

ns_register_filter postauth * /some-site-loc/names/* ::revproxy::upstream -target $target_1_url -url_rewrite_callback my::rewrite_url
ns_register_filter postauth * /some-site-loc/ns-special/* some_call ; # this route I want NaviServer to serve.
ns_register_filter postauth * /some-site-loc/* ::revproxy::upstream -target $target_2_url -url_rewrite_callback my::rewrite_url

The requests to target_1_url and target_2_url work well and as expected. Is there something that I can put in the place of some_call, in the second filter above, that will cause a request to /some-site-loc/ns_special/* to be served by NaviServer itself?


-Tony Kirkham

The filters are processed sequentially. For one URL, it is possible, that multiple filters of the same filter type are processed.... provided that the filter in this chain allow this.

The behavior is controlled by the return value of a filter [1]. When a filter returns "filter_break", no other filter of the same type will be processed. So, if you arrange your filters such that the special case is in the filter chain before the revproxy call, and the filter for the special case returns "filter_break", the revproxy filter should not be called. Check the order of the registered postauth filters on your server with

lmap f [ns_server filters] {if {[lindex $f 2] ne "postauth"} continue; set f}