Integrated ETag / If-None-Match Support
Reported by Ryan Tomayko | April 13th, 2008 @ 05:00 AM | in 0.3.0 Sammy
This is similar to the If-Modified-Since support described in #2 but is a bit more experimental and less thought out:
get '/foo/:id' do
@foo = Foo.find(params[:id])
entity_tag md5(@foo.title + @foo.body)
...
end
If the value provided to entity_tag matches any of the etags provided in the If-None-Match request header, the response is immediately halted with a 304 Not Modified response. Otherwise, the ETag response is set to the value provided and the request continues execution.
ETags are most easily generated as a MD5/SHA checksum of the entire response body (unlike the example above). Unfortunately, this removes the ability to short-circuit a request before heavy processing because the entire response must be generated to check if the response is needed. You get bandwidth savings but limited server resource savings.
So called "deep etags" provide more benefits but are harder to generated. You basically have to generate a checksum by combining individual values from each object that makes a response unique (the example above is an extremely simple and dumbed down illustration of this).
I have not plumbed in any support for generating checksums or other similar niceties -- the etag value must be generated manually. This is something we could add in later, on top of the entity_tag method, or maybe its best to hold off on etag support altogether until some kind of automatic generation is sussed out.
I figured I'd give it a shot since the logic is very similar to that needed to support If-Modified-Since support.
Patch on my master:
http://github.com/rtomayko/sinat...
See REST Tip: Deep etags give you more benefits for more info on generating etags and their benefits.
Comments and changes to this ticket
-
-

Simon Rozet April 19th, 2008 @ 01:00 PM
I don't you if you remember but talked a bit on IRC (my nickname is sr) about how we could guess the ETag/Last-Modified from an object.
I just tried to implement such thing.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
