Skip to content

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:

If-Unmodified-Since: Mon, 18 Feb 2025 12:00:00 GMT

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):

HTTP/1.1 200 OK
Content-Type: text/plain

[Updated document]

Server Response (If Resource Has Changed - Update Denied):

HTTP/1.1 412 Precondition Failed

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:

DELETE /resource HTTP/1.1
Host: example.com
If-Unmodified-Since: Mon, 18 Feb 2025 12:00:00 GMT

Server Response (If Resource Has Not Changed - Deletion Allowed):

HTTP/1.1 204 No Content

Server Response (If Resource Has Changed - Deletion Denied):

HTTP/1.1 412 Precondition Failed

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.