httpetag

Should eTags be unique for same URL but with different request parameters?


Say we are creating a server resource with a set of data with rows 1,2,3 and a REST endpoint that returns one row specified by parameter "row" on GET requests. We have a last modified date that changes for the entire data set and want to use that as the eTag for responses.

My expectation is that clients that request "row=1" and receive the eTag in the response are not going to then use that tag to make a request for "row=2", but only for later queries with "row=1". Therefore it should not matter that the eTag returned is the same (since it is using the modified date of the entire set) for a request with "row" 1, 2, or 3. Is that correct?


Solution

  • You're correct etags don't need to be unique across different resources. They just need to be unique for a specific representation of a specific resource.

    If the URL is different, it's a different resource. With the one exception that a change in the #fragment will still fetch the same resource. I assume you mean values after the ? (query parameters) when you talk about 'request parameters', and indeed these two are different URLs / resources:

    http://example/some-resource?val=1
    http://example/some-resource?val=2
    

    The full 'key' of the cache that the browser maintains actually can also include more information from the HTTP request and response. See the Vary header for more information.