Weak entity tag (source code)

= Weak entity tag

A <weak entity tag> is an <entity tag> explicitly marked `W/` whose validation guarantee does not require distinguishing every change to the <HTTP representation> data. A server may group representations it regards as suitable substitutes, rather than identify each distinct sequence of bytes. The weak marker is case-sensitive.<HTTP Semantics>[§8.8.1, weak validators and origin-defined equivalence; §8.8.3, W/ marking]{ref}

For an invented example, an <HTML> resource sometimes ends its source with an extra newline. Stipulate that this does not change its relevant rendered meaning and that the server considers both forms interchangeable for reuse. It can retain `W/"page-4"` across those two forms. It should change the tag when it no longer regards an older representation as an acceptable substitute. This policy is a server decision, not a license for clients to ignore arbitrary differences.<HTTP Semantics>[§8.8.1, changing weak validators and acceptable substitution]{ref}

Weak comparison ignores whether a tag is marked weak but still compares the opaque value character for character. Consequently `W/"page-4"` weakly matches both `W/"page-4"` and `"page-4"`; it does not match `W/"Page-4"`. Strong comparison fails whenever either operand is a <weak entity tag>, even when their opaque values agree.<HTTP Semantics>[§8.8.3.2, Comparison]{ref}

This distinction supports <HTTP cache validation>. An <HTTP conditional request> with `If-None-Match: W/"page-4"` uses weak comparison, so a matching selected representation can produce `304` for `GET`. An update protected by `If-Match` instead requires a <strong entity tag> comparison and cannot obtain that guarantee from this weak tag.<HTTP Semantics>[§13.1.2, weak comparison and GET result; §13.1.1, strong comparison]{ref}

Weakness concerns the strength of the equivalence assertion. It does not mean that the tag is malformed, that an exchange failed, or that its opaque text measures how similar two representations are.