I have usual happstack case in which we have ServerPart Response MonadPlus in list and. Then msum Chooses the one that does not fail and response generated and returned.
I have opinion that some actions – like cheking cookies – preparing connection context (authorising authenticated user, implementing counts, etc…) should be done in any incoming request – without any path info even defined yet.
Maybe there’s some buzzy word I still not knowing yet, specially for such kinds of staff. Could someone advice please?
If you want to take certain actions for every request, you can add them in the do statement before your routing code. For example:
That will always run
incCounterandcheckUserAuth. Then it will try the various routes.If one of the routes matches, it will then call
logResponse, and then finally return therespwhich will be sent to the user.Note that while
incCounterandcheckUserAuthwill always be run,logResponsewill only be run if one of the parts matches. If none do, then I am pretty sure the code will escape and return a 404. If you wantedlogResponseto always run, then you could add a handler to themsumthat always matches. For example:That will almost always run. If one of the parts matches, but explicitly calls ‘escape’, then I am pretty sure
logResponsestill won’t be run. There are ways of dealing with that as well.But, the short answer is, if you want something to happen even time, just put it before your
msumcode.