JE42
JE42

Reputation: 5169

Response code when etag is expected but not received?

What would be an appropriate HTTP response code for a server to send if it expects the ETag header to be set but the request does not contain it ? Would the most appropriate be BAD REQUEST (400) ?

Upvotes: 1

Views: 1305

Answers (3)

Julian Reschke
Julian Reschke

Reputation: 42075

If what you mean is that a conditional request header field (such as If-None-Match) was missing, then the answer would be status 428 (see https://www.rfc-editor.org/rfc/rfc6585#section-3).

Upvotes: 2

Szocske
Szocske

Reputation: 7661

Is it a conditional GET? Because then a plain 200 OK with full body seems completely appropriate to me in case the validity of the client cache can not be verified.

Upvotes: 0

IMSoP
IMSoP

Reputation: 98015

The description in RFC 2616 defines Status 403 as "The server understood the request, but is refusing to fulfill it."

Since it is explicitly left up to the server to explain why the request was refused, a 403 with a body stating "All requests must include an ETag Header" would seem to be a correct response.

Status 400 is defined in that RFC as being due to "malformed syntax", which is not the same as receiving a request you didn't like the look of.

Upvotes: 2

Related Questions