Search code examples
httpresthttp-status-code-412

Is it OK to return most recent version of the entity in case of a 412 "Precondition failed"


When doing a PUT or DELETE with an "If-Match" header, in case the ETag sent by a client indicates staleness, rather than just returning a 412, I'd like to return the whole up-to-date entity (including its new ETag in the HTTP header), so the client does not have to perform another GET round trip, which they otherwise would certainly do - in my use-case at least they'd do in probably 100% of the cases.

I don't see anything for or against it in the docs for 412: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.13

And looking at, say, status code 409, it doesn't seem to be a problem in general to do whatever one likes with the response body of a 4xx error: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10

So, does anything (especially in the HTTP specs) speak against return the full up-to-date entity and its ETag?


Solution

  • Should be fine:

    All 1xx (informational), 204 (no content), and 304 (not modified) responses MUST NOT include a message-body. All other responses do include a message-body, although it MAY be of zero length.

    Source: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3