users@jersey.java.net

[Jersey] Re: Should I include media type in my ETag?

From: Jan Algermissen <algermissen1971_at_mac.com>
Date: Wed, 2 Nov 2011 10:09:45 +0100

On Nov 2, 2011, at 1:06 AM, Jason Erickson wrote:

> When adding an ETag to an HTTP response, should I include the media type? Of course, I understand that the ETag is opaque, but here is an example:
>
> • Say I have a client that requests a Person in application/json. I look it up and create my ETag and send back the JSON representation of the person
> • Now the same client makes another request for the same person (which has not been modified) at the same URI but wants it in application/xml.

ETags apply to byte-equality. Two entities with different byte content must not have the same ETag.


> Clearly it is incorrect to simply return a 304, but my question is, in the second request, would I expect the ETags to match but no cache based on the Accept header (or the content header). Also, is it even possible that the cache will have two representations from the same URI,

Yes. Because Content-Negotiation can result in different entities for the same response. Servers send the Vary header to indicate that and caches use a combination of URI and Vary to create the hash key.

Give the HTTP spec's section on caching a close read - its all in there:

http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-17

Jan


> or would you always get have an invalid cache every time your Content-Type switched?
>