HTTP conditional request (source code)

= HTTP conditional request
{c}

An <HTTP conditional request> carries one or more preconditions to be evaluated before applying its <HTTP request method>. The condition can ask whether the selected <HTTP representation> still has a previously observed <entity tag>. This makes the request depend on the state the client knows, rather than applying an operation unconditionally.<HTTP Semantics>[§13, Conditional Requests; §13.2.1, evaluation after normal request checks]{ref}

For <HTTP cache validation>, suppose an earlier retrieval of `/color` stored the text `blue` with <entity tag> `"v7"`. A later `GET` with `If-None-Match: "v7"` asks for the representation only if its tag no longer matches. If the selected representation still matches, the condition is false and the server returns status `304` instead of transferring the representation data again. If it has changed, an otherwise successful retrieval can return the new data.<HTTP Semantics>[§13.1.2, If-None-Match and the GET/HEAD outcome]{ref}

A second use prevents overwriting another client's work. Suppose two clients read version `"v7"`. The first makes an update and the server assigns version `"v8"`. The second submits a different `PUT` with `If-Match: "v7"`. The stale tag does not match, so the server must not apply that update; in this example it returns `412`. Checking and applying the condition as part of the operation prevents the second client from silently replacing the first client's changes.<HTTP Semantics>[§13.1.1, If-Match, lost updates and failed-precondition handling]{ref}

The two field names deliberately use different comparisons: `If-Match` requires <strong entity tag> comparison, while `If-None-Match` uses weak comparison and can match a <weak entity tag>. Failed `If-Match` need not always yield `412`: the specification permits a success response when the requested change appears already applied. Authentication, redirects and other normal request checks also precede precondition evaluation. An <HTTP conditional request> therefore combines method semantics, a particular condition and the specified evaluation order.