Conditional Requests

Most of this chapter should have been discussed in Caching and Range Requests

HTTP conditional requests are requests that are executed differently, depending on the value of specific headers. These headers define a precondition, and the result of the request will be different if the precondition is met or not (MDN).

Request headers

If-Match

Succeeds if the requested resource matches one of the given ETag(s). The server can indicate a successful response with status code 100 (Continue)* or 200 (OK).

If the condition fails, the server can respond with 412 (Precondition Failed).

If-Match: "<etag_value>"
If-Match: "<etag_value>", "<etag_value>", ...
If-Match: *

(*) E.g. for a PUT request, to indicate that the client wants to override the existing document (W3)

If-None-Match

Succeeds if the requested resource does not match any of the given ETag(s). The server sends back the requested resource with 200 (OK).

If the condition fails, the server can respond with 304 (Not Modified) or 412 (Precondition Failed).

If-None-Match: "<etag_value>"
If-None-Match: "<etag_value>", "<etag_value>", ...
If-None-Match: *

If-Modified-Since

Succeeds if the requested resource has been modified after the given date. The server sends back the requested resource with 200 (OK).

If the condition fails, the server can respond with 304 (Not Modified) or 412 (Precondition Failed).

If-Modified-Since: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT

If-Unmodified-Since

Succeeds if the requested resource has not been modified after the given date. The server can indicate a successful response with status code 200 (OK).

If the condition fails, the server can respond with 412 (Precondition Failed).

If-Unmodified-Since: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT

If-Range

Succeeds if the requested resource has not been modified, given the date or an ETag. The server can indicate a successful response with status code 206 (Partial Content) if it sends the range requested in Range request header, or 200 (OK) if it sends the full resource.

If the condition fails, the server can respond with 416 (Range Not Satisfiable) or 412 (Precondition Failed).

If-Range: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
If-Range: <etag>

References