Nick Dancer
Nick Dancer

Reputation: 335

ETag changes when Rack::Deflater is enabled

have stumbled upon something weird when enabling Rack::Deflater to gzip my response body. Perhaps i'm missing something but with this enabled the response is compressed however the ETag for the resource changes on every single request. This is forcing the app to respond each time rather then sending a 304. This works without Rack::Deflater enabled and I have verified that the page source is not changing. Am running a rails app with thin as the web server.

Gemfile.lock https://gist.github.com/2510816

Is there someway I can get a bit more output from rack middleware so I might be able to see whats going on?

Thanks in advance.

Upvotes: 6

Views: 757

Answers (1)

Nick Dancer
Nick Dancer

Reputation: 335

So I have fixed my original issue but still not quite getting the desired results. Turns out Rack::Deflater needs to be before Rack::ETag in the middleware stack. Still not sure why this would cause the ETag to change every request but sure enough if I change config.middleware.use "Rack::Deflater" to config.middleware.insert_before "Rack::ETag", "Rack::Deflater" then the ETag becomes consistent across requests. I'm still not getting a 304 but I think thats because of incorrect cache-control headers and unrelated to the original problem. Hopefully this helps someone in the future.

Upvotes: 11

Related Questions