Search code examples
httphttp-erroretag

What http error code to return when "ETag" header field is malformed?


RFC 7232 states the format of the If-Match and If-None-Match header fields. What http error code should be returned when the format of the header is wrong? 412 precondiction failed or 400 bad request? The RFC speaks only about "evaluate the If-Match precondition".


Solution

  • 400 is the appropriate status code here, since this is a case of "malformed request syntax". 412 would be a misleading response, since the client wouldn't know there was anything wrong with how it formatted its request.