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

Already on GitHub? Sign in to your account

response body is not available to after filters #159

rfletcher opened this Issue Jan 9, 2011 · 2 comments


None yet
2 participants

I've found a few people asking this question in various places, but can't find a definitive answer as to whether it's a bug or by design. Rather than repeat the question, here's one of the ones I found on Google Groups (http://groups.google.com/group/sinatrarb/browse_thread/thread/6e745213966ea96f):

in Sinatra 1.x, the new after filter feature does not have access to
response.body (to read or modify). Given this simple app:
require 'rubygems'
require 'sinatra'
after { p response }
get('/') { etag "abc"; "HELLO" }

The response.body comes out as []:
#<Sinatra::Response:0x188bee4 @Body=[], ..., @Header={"ETag"=>""abc"", ...>

Notice that the headers set in route block are available. I don't know
if this is expected behaviour or not -- there are no tests for this in
the test suite, but it seems counter-intuitive to me, and the the
README states that:

After filter are evaluated after each request within the context of the
request and can also modify the request and response.

Can someone confirm what's the real meaning?
(My use-case would be to automatically set ETag in an after, globally
in the application -- doing MD5 of the body etc.)


rkh commented Jan 10, 2011

There was a ticket in the lighthouse tracker. The conclusion was that this is by design-ish. Also, there was no use case where you wouldn't be better off with a middleware.

Thanks, I'll look into Rack middleware.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment