If-Unmodified-Since
Description
The If-Unmodified-Since
request header is an HTTP conditional request header
used to ensure that a request is only processed if the requested resource has
not been modified since a specified date and time.
This header is primarily used in conjunction with methods that modify resources,
such as PUT
and DELETE
, to prevent unintended overwrites or deletions. If
the resource has been modified after the specified date, the server responds
with a 412 Precondition Failed
status, indicating that the request should not
proceed.
This header is useful for concurrency control, ensuring that clients do not inadvertently overwrite newer versions of a resource when performing updates or deletions.
Syntax
The If-Unmodified-Since
header is used in an HTTP request as follows:
This header must use the HTTP-date format as specified in RFC 7231.
Examples
Preventing Overwrites with PUT
A client attempts to update a resource only if it has not been modified since the specified date.
Client Request:
PUT /document.txt HTTP/1.1
Host: example.com
If-Unmodified-Since: Mon, 18 Feb 2025 12:00:00 GMT
Content-Type: text/plain
Updated content.
Server Response (If Resource Has Not Changed - Update Allowed):
Server Response (If Resource Has Changed - Update Denied):
Ensuring Safe Deletion with DELETE
A client tries to delete a resource only if it has not been modified since the specified date.
Client Request:
Server Response (If Resource Has Not Changed - Deletion Allowed):
Server Response (If Resource Has Changed - Deletion Denied):
Summary
The If-Unmodified-Since
request header is a valuable mechanism for preventing
unintended modifications to resources. It is particularly useful in scenarios
where multiple clients may attempt to update or delete a resource
simultaneously. By ensuring that the operation proceeds only if the resource
remains unchanged, this header helps maintain data integrity and minimizes
conflicts in concurrent environments.