Consider a REST API endpoint that returns a resource with an ETag header. A client sends a GET request with the header If-None-Match set to the current ETag value of the resource.
What HTTP status code will the server return if the resource has not changed?
GET /resource HTTP/1.1 Host: example.com If-None-Match: "abc123etag"
Think about what the server does when the resource has not changed since the client last fetched it.
If the ETag sent by the client matches the current ETag of the resource, the server responds with 304 Not Modified and does not send the resource body again. This saves bandwidth.
Choose the best description of what the ETag header does in HTTP responses.
ETag helps clients know if the resource has changed or not.
The ETag header is a unique string that identifies a specific version of a resource. Clients use it to check if the resource has changed since last fetched.
Given the following server code snippet handling ETag conditional requests, identify the bug causing the server to always return 200 OK even when the resource is unchanged.
etag = get_current_etag(resource) if request.headers.get('If-None-Match') == etag: return resource, 304, {'ETag': etag} else: return resource, 200, {'ETag': etag}
Check the status code returned when the ETags match.
When the client's If-None-Match header matches the current ETag, the server must return 304 Not Modified status code without the resource body. Returning 200 always sends the full resource.
Choose the correct syntax for the ETag header in an HTTP response.
ETag values are usually quoted strings.
The ETag header value must be enclosed in double quotes to be valid according to HTTP standards.
A client makes three GET requests to a REST API for the same resource with ETag "v1". The server responds:
- First request: 200 OK with ETag "v1"
- Second request: If-None-Match: "v1" → 304 Not Modified
- Third request: If-None-Match: "v1" → 304 Not Modified
How many copies of the resource are stored in the client's cache after these requests?
Think about how caching works with 304 responses.
The client caches one copy of the resource after the first 200 OK response. Subsequent 304 responses mean the cached copy is still valid, so no new copies are stored.