Should I include a media type in my ETag?

When adding an ETag to an HTTP response, should I include a media type? Of course, I understand that the ETag is opaque, but here is an example:

  • Let's say I have a client that requests Person in the / json application. I search for it 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 changed) in the same URI, but wants it in application / xml.

It is clear that it is incorrect to simply return 304, but my question is that in the second request I would expect ETags to match, but there would be no cache based on the Accept header (or the content header). Also, is it possible that the cache will have two views from the same URI, or will it always have an invalid cache each time you switch your Content-Type?

+6
source share
2 answers

Different views require different object tags.

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

+5
source

I believe that you can send the same Etag for different submissions. As long as you indicate that they should be cached as two different objects, in your answer. This can be done using the Vary field as described in RFC 2616

http://www.ietf.org/rfc/rfc2616.txt

14.44 Vary

The value of the Vary field indicates a set of request header fields that fully determines while the response is fresh whether the cache is allowed to use the response to respond to a subsequent request without re-certification. For unclean or obsolete responses, the Vary field value informs the user agent of the criteria that were used to select the view.

Using Vary: Accept should be appropriate.

-1
source

Source: https://habr.com/ru/post/900570/


All Articles