The If-None-Match header is used to make a request conditional. It contains an ETag value, and the server compares it with the current ETag of the resource. If they match, the server responds with 304 Not Modified to save bandwidth by not sending the resource again.
If-None-Match header matching the current ETag of the resource, what status code does the server respond with?When the ETag in If-None-Match matches the current resource ETag, the server returns 304 Not Modified to indicate the cached version is still valid.
if request.headers['If-None-Match'] == resource.etag:
return 200, resource.data
else:
return 304, None
Why is this incorrect?The code returns 200 OK with the resource data when the ETags match, but it should return 304 Not Modified with no body to save bandwidth.
The ETag header must be included in a 304 response to indicate the current version of the resource.
A 304 Not Modified response has no body. The server sends headers only, so zero bytes are sent in the body.