Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing the http.ResponseWriter means Renderer must be the last handler #6

Open
tysonstewart opened this issue Feb 17, 2014 · 1 comment

Comments

@tysonstewart
Copy link

I discovered this while trying to implement a cache handler. We don't want to cache all of our requests, so we'd like to pass the cache handler to the router. In order to do this, however, Renderer has to be passed to every route as well and after the cache.

Example:

martiniServer.Use(render.Renderer())
router := martini.NewRouter()
// Caching won't work here because it wants to intercept and
// and replace the http.ResponseWriter, but Render has a
// reference to the original ResponseWriter. The replaced one
// will never be used.
router.Get("/", cache, func(r render.Render) {
    r.HTML(200, "index", "Welcome")
}

Is it necessary to capture the ResponseWriter? Is there a better way to do what I'm trying to do?

@codegangsta
Copy link
Member

This is because render uses the ResponseWriter that is injected into it's handler function.

render.Renderer could grab the ResponseWriter from the context right before it renders things, but that would require some changes and introduce some undesired behavior. I'm willing to explore the idea given that it doesn't break existing functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants