Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails, how to disable/turn off ETag

Greetings,

How do I turn off ETag(s) in Ruby on Rails v2.3.5

When I do a direct request to to the RoR/Mongrel an ETag header is present.

TIA,

-daniel

like image 500
Daniel Avatar asked Jan 19 '10 00:01

Daniel


3 Answers

much easier:

config.middleware.delete Rack::ETag
like image 183
malik Avatar answered Nov 20 '22 23:11

malik


Putting response.etag = nil in a before_filter does not work. The etag is generated just before the response is send (it's caluculated from the body so after all rendering has been done).

The proper workaround to disable etag use and generation (and so save the time spend in md5) it this monkey patch:

module ActionController
  class Request
    # never match any incomming etag
    def etag_matches?(etag)
      false
    end
  end

  class Response
    # fake rails that our response already has an etag set and so none is generated automatically
    def etag?
      true
    end
  end
end
like image 21
gucki Avatar answered Nov 21 '22 00:11

gucki


There's an etag setter method on the ActionController::Response object, which deletes the ETag HTTP header if it's blank, so you should just be able to clear it in your controller (probably in a before filter):

response.etag = nil
like image 1
John Topley Avatar answered Nov 20 '22 22:11

John Topley