More
More
412 Precondition Failed
A condition in the request headers, such as If-Match, was not met.
- Code
412- Reason phrase
- Precondition Failed
- Class
- 4xx Client error
- Defined in
- RFC 9110 section 15.5.13
- Cacheable by default
- No
What it means
Client error: the problem lies with the request. Repeating it unchanged will normally fail again.
When a server should send it. When a condition in the request headers (If-Match, If-Unmodified-Since, If-None-Match on a write) is false. It is the server half of optimistic locking: the client's copy is out of date.
Common causes. Optimistic locking: the resource changed since you last fetched it.
What to do. Fetch the current version and its ETag, then retry.
How clients and crawlers treat it
Browsers and HTTP clients. API clients re-fetch the resource to get the current ETag, then retry. Browsers send conditional headers only for their own cache checks, which give 304 rather than 412.
Google Search. Like every 4xx except 429, it tells Google the content does not exist: an indexed URL is removed from the index, and a new one is not processed. Crawl frequency for the URL gradually drops. Source: Google Search Central, How HTTP status codes, and network and DNS errors affect Google Search.
Caching. Not cacheable by default (RFC 9110 section 15.1 does not list it). A cache stores it only when the response says so with Cache-Control or Expires.
Example response
HTTP/1.1 412 Precondition Failed Content-Type: text/plain; charset=utf-8 Precondition Failed
How to send 412
location /example {
return 412;
}
RewriteEngine On RewriteRule ^example$ - [R=412,L]
http_response_code(412); echo 'Precondition Failed'; exit;
res.writeHead(412, { 'Content-Type': 'text/plain' });
res.end('Precondition Failed');
# in a view function return 'Precondition Failed', 412
Change the paths to suit. In nginx, add_header needs always to apply to error responses.
Related codes
- 428Precondition RequiredThe server requires the request to be conditional, such as with If-Match.
- 409ConflictThe request conflicts with the current state of the resource.
- 304Not ModifiedThe cached copy the client already has is still current, so no body is sent.
All status codes · All 4xx codes
Names and numbers from the IANA HTTP Status Code Registry. Google Search behaviour as documented by Google Search Central.