Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Different Etags for Different Representations of the Same Resource?

Tags:

rest

etag

I understand the use of etags for optimistic concurrency control (e.g. in a RESTful style of architecture), and I've read that etags should be different for different representations of the same resource. Why is that?

Ultimately aren't we interested in knowing if the resource has changed so we can handle concurrent modifications? I'm having a hard time even envisioning when a resource's representation would change without the resource itself changing, so I'm obviously missing some basic understanding.

like image 763
erturne Avatar asked Apr 22 '11 02:04

erturne


People also ask

What is the advantage of ETag response header in a response message?

The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource. It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content was not changed.

How are weak ETags different from strong ETags?

Strong v/s Weak ETags ETag supports strong and weak validation of the resource. Strong ETag indicates that resource content is same for response body and the response headers. Weak ETag indicates that the two representations are semantically equivalent. It compares only the response body.

How does ETag caching work?

The ETag (or Entity Tag) works in a similar way to the Last-Modified header except its value is a digest of the resources contents (for instance, an MD5 hash). This allows the server to identify if the cached contents of the resource are different to the most recent version.

What is the purpose of ETag?

An ETag (entity tag) is an HTTP header that is used to validate that the client (such as a mobile device) has the most recent version of a record. When a GET request is made, the ETag is returned as a response header. The ETag also allows the client to make conditional requests.


1 Answers

Good question, and I think it's a matter of some debate.

I think that most would say that the ETag represents not only the resource version, but also the content type. This would make sense for caching responses based on content type, language, etc.

Check out the following links:

  • Wikipedia article section about strong vs weak ETags: http://en.wikipedia.org/wiki/HTTP_ETag#Strong_and_weak_validation
  • An informative discussion on content encoding and ETags: http://www.gossamer-threads.com/lists/apache/dev/339577
like image 179
anon Avatar answered Sep 23 '22 15:09

anon