Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 553
Nick Dancer Avatar asked Apr 27 '12 17:04

Nick Dancer


1 Answers

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.

like image 178
Nick Dancer Avatar answered Oct 22 '22 06:10

Nick Dancer