How to enable Etag in development mode in rails 3.2.12 using WEbrick / Thin

StackOverflow https://stackoverflow.com/questions/16903759

  •  30-05-2022
  •  | 
  •  

Question

I am running Webricks/Thin server locally for my development environment however i couldn't get to return Etag in my response.

I've tried various options suggested on SO to add Etag or ConditionalGet rack middleware components but to no avail. Here is the snippet on my development.rb file

config.middleware.use Rack::Cors do
allow do
  origins 'xyz:3000', 'abc:3000'
  resource '*', :headers => :any, :methods => [:get, :post, :options]
end

config.middleware.insert_before(Rack::Cors, Rack::ConditionalGet)
config.consider_all_requests_local       = true
config.action_controller.perform_caching = true

Here is the sample response header from a request and thats missing the Etag header or HTTP_IF_NONE_MATCH and HTTP_IF_MODIFIED_SINCE headers and thus all requests return 200 OK and never the 304 Not Modified which

> curl --head -I mylocalhosturl
HTTP/1.1 200 OK 
Last-Modified: Mon, 04 Feb 2013 23:49:11 GMT
Content-Type: application/json; charset=utf-8
Cache-Control: must-revalidate, private, max-age=0
X-Meta-Request-Version: 0.2.1
X-Ua-Compatible: IE=Edge
X-Request-Id: a06b5c3aeff8191ad22ab7d23433b076
X-Runtime: 0.217688
X-Rack-Cache: miss
X-Miniprofiler-Ids: ["470heu3ps6wht3tuqgdr","qdjrpkjus6pzw6ed28ex","egfngxkdtl2f2m1w7r9n","b3dlozxj3hyb9bq2i2fi","k7x41fq7anewz5jf0nm1","unojexyqklkjdew8dkti","rjwo48jd8pw8c0h0jb38","82d8g9o6agzoam7acxgi","tk577xwtgtfn7u1mrvqo","e8ih8byjbm2jfmbyl5tf"]
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16)
Date: Mon, 03 Jun 2013 18:34:31 GMT
Connection: Keep-Alive
Set-Cookie: __profilin=p%3Dt; path=/
Set-Cookie: __profilin=p%3Dt; path=/
Set-Cookie: __profilin=p%3Dt; path=/

Interesting this is not an issue on production which uses similar configurations AFAIK but nginx/1.2.0 as the server. Any ideas on enabling Etags in rails development mode appreciated.

Was it helpful?

Solution

Remove rack-mini-profiler gem from your project and restart the server.

For some reason rack-mini-profiler gem will strip out the Etags. I found this SO post because I was looking to figure out why it strips out the Etags.

Update

You can also disable that behavior according to the Official Docs like this

Rack::MiniProfiler.config.disable_caching = false

Please note that disabling that behavior may introduce some nasty bugs with rack-mini-profiler as mentioned in the documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top