bleedingwolf / Ratpack

A micro web framework for Groovy
Other
210 stars 4 forks source link

best way to implement a before Filter ? #16

Open buckyball opened 13 years ago

buckyball commented 13 years ago

How would you add a "before filter" to intercept requests ? I implemented some quick before filter like this:

RatpackServlet.groovy:

def beforeHandler = app.getHandler("BEFORE", path)
if (beforeHandler && beforeHandler!=null) {
                    try{
                        beforeHandler.delegate.request = req
                        beforeHandler.delegate.response = res
                        beforeHandler.call()
                    } catch (Exception ex){
                        log "Exeption in before Handler: " + ex.inspect()
                    }
}

But what I'm missing now is some sort of wildcard route like that:

before(/*){
}

Or:

before(/secure/*){
}

to apply the filter to every request.

justinvoss commented 13 years ago

I think "before" and "after" filters are great ideas, I just haven't had time to put any code together for them. If you want to submit a patch, I'd be glad to look at it; otherwise, I think this will have to wait for the next release.