Proposed Solution
HttpAnswer, a wrapper on native HTTP response, has a method skip. The purpose of this method is to skip the number of handlers in the handlers sequence for the current route.
HttpAnswer is not suitable to hold methods related to request handlers. Hence this method should be removed from this class. Instead, we should provide a resource, say handelersChain, for this functionality.
function authentication(asked, answer, giveMe){
//.. not authorized. skip all, redirect to login page
}
HttpAnswer should call it internally in case of redirect, close, end response.
HandlersChain can also skip to the particular handler by providing its name instead of a number.
Implementation thoughts
HandlerRunner : runs the bundle of preHandler, handler, postHandler
routesManager: Run the sequence of handlerRunners for a particular route.
routesManager can check handlersChain before executing next handlerRunner. It is currently using HttpAnswer.skip for the same.
HttpAnswer will also have the reference of handlersChain so that it can set it in case of redirect, close, or end. Another approach can be that HttpAnswer can emit the event, say answered or redirected. We as a framework will update handlersChain then so that routesManager will skip the rest chain.
We can also consider HandlersChain as a linked list which returns an iterator. routesManager just checks it hasNext to execute.