What is 428 Precondition Required: Solutions for Web Developers

HTTP status codes are integral to the communication between a web server and a client, providing immediate feedback about the result of an HTTP request. At times, a client’s request to a server may be met with the status code 428, indicating “Precondition Required.” This code is part of the expansion of the HTTP protocol and serves a specific purpose in conditional requests, which are HTTP requests that are executed only if certain conditions are met.

website error code

A “428 Precondition Required” status arises when the server requires certain preconditions to be fulfilled before proceeding with the request. This is implemented to prevent problems such as the ‘lost update’ issue, which occurs when multiple parties attempt to modify a resource on the server concurrently. For instance, when a client’s update request lacks a necessary precondition header like “If-Unmodified-Since” or “If-Match,” which are used to ensure that the client is modifying the most recent version of a resource, the server responds with this status code.

Addressing a 428 error requires the client to resend the request with the appropriate precondition header(s). These headers allow the server to check if the conditions for the request have been met. For example, an “If-Match” header can be provided with the request, containing the entity tag (ETag) of the version of the resource that the client intends to modify. If the ETag sent by the client matches the current ETag of the resource on the server, the request will proceed; otherwise, the server will typically return a “412 Precondition Failed” status, prompting further action from the client.

Understanding HTTP 428 Precondition Required

In this section, we will explore the “HTTP 428 Precondition Required” status code, which involves making conditional requests to the server to ensure resource integrity.

Definition of HTTP 428 Precondition Required

HTTP 428 Precondition Required is a status code defined in RFC 6585 that indicates the server requires the incoming HTTP request to be conditional. This means that certain preconditions must be met for the server to process the request. It is a method to prevent the “lost update” problem, which can occur when a resource is being accessed concurrently by different clients.

Preconditions and HTTP Conditional Requests

Conditional requests are a fundamental aspect of HTTP designed to optimize web communication. They allow a client to specify preconditions—criteria that must be met before a server will process a request. Common HTTP headers used in conditional requests include If-Match, If-None-Match, If-Modified-Since, and If-Unmodified-Since. When the server stipulates that a request must be conditional and these preconditions are not provided, or the provided preconditions do not match the server’s current state of the resource, a client may receive a 428 Precondition Required response.

The Role of ETags in Conditional Requests

An ETag, or entity tag, is a unique identifier assigned by a server to a specific version of a resource. ETags are used in the If-Match and If-None-Match headers to make requests conditional. The client can include these headers with their request, and if the ETag values do not match the current version on the server, the server will deny the request and may return a 428 Precondition Required status. This ensures that clients do not unknowingly overwrite concurrent changes made to the resource by others.

Resolving the 428 Precondition Required Error

To effectively resolve the 428 Precondition Required error, one must carefully identify what key precondition headers are missing, understand the client-server interaction for configuration, and follow best practices for troubleshooting and prevention.

Identifying the Missing Precondition Headers

The first step in resolving a 428 Precondition Required error is to check for missing conditional headers in the request. Commonly required headers include If-Match and If-Unmodified-Since. These headers are used to prevent the lost update problem, ensuring the client is updating the most recent version of the resource.

  • If-Match: The client expects the server’s current entity tag (ETag) to match the one provided.
  • If-Unmodified-Since: The client expects the resource on the server has not been modified since the date provided.

A lack of these headers or a mismatch between the server’s state and the precondition values triggers the 428 error. If the precondition header is missing, the server cannot process the PUT, DELETE, or POST request aimed at updating the resource.

Server Configuration and Client-Server Interaction

The server configuration must be set up to handle conditional requests appropriately. When a client sends a PUT or DELETE request without the expected preconditions, the server responds with a 428 status. Alternatively, if the provided precondition does not match the server side state, the response should be 412 Precondition Failed.

To amend this situation, ensure that the server is capable of recognizing and validating precondition headers. The client must be configured to include these headers in requests, helping to ascertain that updates occur only when conditions on the server meet the client’s expectations.

Best Practices for Troubleshooting and Prevention

Troubleshooting the 428 Precondition Required error involves a systematic approach:

  1. Review request logs for missing or incorrect headers.
  2. Validate that the server supports and correctly processes the conditional headers.
  3. Confirm that the client includes accurate precondition headers when attempting updates.

For prevention, adhere to these guidelines:

  • Server-Side: Regularly verify the server’s ability to handle conditional requests and respond with the correct status codes.
  • Client-Side: Implement checks to ensure all update requests are conditional, using If-Match and If-Unmodified-Since headers.

By addressing these specific areas, one can reduce delays and errors, contributing to a more successful and efficient client-server interaction.


Published on: 2024-01-02
Updated on: 2024-01-02

Avatar for Isaac Adams-Hands

Isaac Adams-Hands

Isaac Adams-Hands is the SEO Director at SEO North, a company that provides Search Engine Optimization services. As an SEO Professional, Isaac has considerable expertise in On-page SEO, Off-page SEO, and Technical SEO, which gives him a leg up against the competition.