Entity tag (source code)

= Entity tag

An <entity tag> is an opaque validator associated with a selected <HTTP representation> and commonly supplied in an `ETag` <HTTP header field>. It allows requests to refer to a previously observed version or equivalence class without interpreting the representation's contents. The tag's spelling need not reveal how the server generated it.<HTTP Semantics>[§8.8.3, entity tags and opaque validators]{ref}

A <strong entity tag> has no weak marker; a <weak entity tag> has the prefix `W/`. Strong comparison succeeds only when both tags are non-weak and their opaque values match character by character. Weak comparison checks the opaque values while ignoring whether either tag is marked weak.<HTTP Semantics>[§8.8.3.2, strong and weak comparison]{ref}

For example, `"v1"` and `W/"v1"` match weakly but not strongly. Two occurrences of `"v1"` match under either comparison. Tags `"AbC"` and `"abc"` match under neither: field-name case insensitivity does not make the opaque value case-insensitive.

A useful <HTTP conditional request> illustrates the purpose. Suppose a client retains representation data tagged `"v1"`, then sends `GET` with `If-None-Match: "v1"`. If the selected current tag matches, this precondition fails and the server returns `304` without transferring that response content. The retained data can then be used according to the applicable caching rules. `If-None-Match` uses weak comparison, while `If-Match` uses strong comparison.<HTTP Semantics>[§§13.1.1–13.1.2, comparison rules and conditional outcomes]{ref}

An <entity tag> is therefore a protocol validator, not an instruction to lowercase or decode its opaque string. Different representations of one resource can require different validators. Compare the tag for the selected representation under the comparison rule required by the field, rather than assuming that equal resource URLs alone establish equal data.