Evgeniy Berezovsky
Evgeniy Berezovsky

Reputation: 19248

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?

Upvotes: 1

Views: 174

Answers (2)

Evgeniy Berezovsky
Evgeniy Berezovsky

Reputation: 19248

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

Upvotes: 1

Julian Reschke
Julian Reschke

Reputation: 42045

What is the request? GET with If-None-Match? In that case, the server isn't supposed to return 412 anyway.

For PUT, DELETE, you certainly can return the current representation. For large representations, it will be inconvenient for clients that don't need it though.

You may also want to label the payload as representation of the resource by using the Location header; see http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-16.html#identifying.response.associated.with.representation.

Upvotes: 0

Related Questions