codegangsta/martini — pull request #83 by dylanmei (2013-11-26 22:40:02+00:00)
Title: Allow route-handlers to run after response is modified 

Martini does not allow middleware-/route-handlers to run once an earlier handler has modified the response. While it's generally good to protect us from doing silly things, it limits our ability to compose the flow that best suits our needs.

// ThingHandler invoked because logThing does not modify response
r.Get("/thing", logThing, ThingHandler)

// logThing never invoked because ThingHandler modifies response
r.Get("/thing", ThingHandler, logThing)

Reasons I would want to run *logThing* after *ThingHandler* include being able to react to, or log the HTTP status produced by the previous handler. One way I can do this now is with a middleware handler, which is convenient unless I only want to log this one route. Another way is to write this

r.Get("/thing", func(c martini.Context) {
c.Invoke(ThingHandler)
c.Invoke(logThing)
}

Which is fine but I'm working around a fragile Martini constraint, and I'm losing the benefits I get from running my handlers within the *route.Handle* loop. We should be empowered to run handlers that we know are not modifying the response.