
What Is a Conditional Request?
A conditional request is an HTTP request whose handling depends on a condition supplied through a request header. The recipient checks that condition against the target resource before deciding how to proceed.
Conditional requests commonly check whether content has changed since an earlier retrieval. They can also prevent an update from overwriting someone else’s changes or help a download resume against the correct version of a file.
The outcome depends on both the request method and the condition. An unchanged image might produce a response without its body, while an outdated editing request might be rejected.
How Conditional Requests Work
A validator is information used to check a resource’s state. HTTP commonly uses an ETag, which identifies a representation’s version, or a Last-Modified timestamp.
A client can retain these values from an earlier response and include them in a later conditional request. The recipient evaluates the relevant precondition rather than requiring the client to download and compare the entire resource.
Validator strength matters. Some comparisons permit equivalent content, while others require an exact match suitable for protecting updates or combining downloaded bytes.
Choosing a Conditional Header
Different headers express different conditions:
| Header | Condition or purpose |
|---|---|
If-None-Match
|
Proceed when none of the supplied ETags matches the selected representation |
If-Modified-Since
|
For GET or HEAD, proceed when the representation changed after the supplied date |
If-Match
|
Proceed when a supplied ETag strongly matches a current representation |
If-Unmodified-Since
|
Proceed when the representation has not changed after the supplied date |
If-Range
|
Apply a requested byte range only when the validator still matches |
These headers have defined evaluation rules. For example, If-None-Match takes precedence over If-Modified-Since, while If-Match takes precedence over If-Unmodified-Since.
Common Uses of Conditional Requests
Revalidating Cached Content
Suppose a browser has stored a campaign image and its ETag. When validation becomes necessary, it can send a GET request containing If-None-Match.
If the validator matches, the recipient can return 304 Not Modified without retransmitting the image body. The browser reuses its stored content. If the image has changed, an otherwise successful request normally receives the current representation instead.
Preventing Conflicting Updates
An application can attach If-Match to an update request to specify the version it intends to modify.
For example, two editors might open the same asset description. After the first saves a change, the second editor’s validator no longer matches. The server can return 412 Precondition Failed rather than apply the outdated update, then offer a refresh or conflict-resolution step.
Resuming Downloads
A client with part of a media file can combine Range with If-Range. If the validator matches and the range is supported and satisfiable, the server can send the requested portion.
If the validator does not match, the server ignores the range and sends the complete current representation instead. This helps avoid joining bytes from different versions. Weak ETags cannot be used in If-Range.
