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
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
I am working in Rails 4 on WEBrick, trying to get a response to cache until it expires at a specific time each day. It looks like the auto-generated ETag is interfering with the expiration cache which is why I searched for this answer. I didn't find anything helpful here, but I did solve my problem, so I'll share.
tl;dr Set the
Last-Modified
headerBut set it to what? In my situation I was trying to optimize a web service that returned the results of a process that runs at the same time every day. My response headers ended up looking like this:
First you want to explicitly write the
Cache-Control
header to overwrite whatever the default is. I set mine to be 24 hours to coincide with the maximum of my expiration header. I set the expiration header with a function the looks something like this:The getLastModified function returns exactly 24 hours less than the getCacheTime function. It seems that setting this will suppress the ETag (another validation caching header) at least in my current development environment.
much easier:
I don't think they are on by default.
My understanding is that they need to be explicitly set using stale?/fresh_when call or similar.
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:
There's an
etag
setter method on theActionController::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):Why not add a before_filter in your application controller which sets etag to nil?