B4J Question Multiple Handler's & Order

Squiffy

Active Member
Licensed User
Longtime User
*reposted from B4a (error)*

Hi.
I want all incoming requests to my server to pass through a verification filter *except* the "/login" path. So can I specify the order the handlers/filters are run in? So for example if I have this :

srvr.AddHandler("/login","LoginUser",False)
srvr.AddFilter("/*","VerifyUser",False)
srvr.AddHandler("/clients","Clients",False)

and set VerifyUser to return false, then call in with http://blah.com/login, the VerifyUser always gets called first.

Is there a way to ensure the order that handlers/filters are called? Or am I approaching this wrong?
 

Roycefer

Well-Known Member
Licensed User
Longtime User
When a request comes in, it is matched against any of the handlers. If a match is found, it is matched against any filter criteria. If it matches a filter criteria, it is passed through the filter before the handler executes. If not, it just goes straight to the handler for execution. The order in which handlers and filters were added has no bearing.

In order to accomplish what I think you're trying to accomplish, add your filter as you have done. Then, inside the Filter() sub of the VerifyUser Filter, you can test req.RequestURI to see if it equals "login". If it does, returning True will allow the login request to proceed to its handler for execution.
 
Upvote 0
Top