Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I include media type in my ETag?

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.

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, or would you always have an invalid cache every time your Content-Type switched?

like image 585
jhericks Avatar asked Nov 01 '11 22:11

jhericks


People also ask

What is the purpose of ETag header?

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.

What is ETag txt?

An entity tag (ETag) is an HTTP header used for Web cache validation and conditional requests from browsers for resources. Etags use persistent identification elements (PIE) that have been tagged to the user's browser.

Is ETag case sensitive?

The standard says that one must use a "strong validator" for handling ETag: thus, ETags must be treated as opaque values and matched accordingly (i.e. case sensitive).


1 Answers

Different representations need different entity tags.

See http://trac.tools.ietf.org/wg/httpbis/trac/ticket/39.

like image 112
Julian Reschke Avatar answered Nov 10 '22 00:11

Julian Reschke