Complete the code to set the ETag header in the HTTP response.
response.headers['ETag'] = [1]
The ETag header must be set to a string value representing the resource version, such as a hash or unique identifier.
Complete the code to check if the client's ETag matches the server's ETag.
if request.headers.get('If-None-Match') == [1]:
The server compares the client's 'If-None-Match' header to the current ETag string to decide if the resource has changed.
Fix the error in the code to return 304 Not Modified when ETags match.
if request.headers.get('If-None-Match') == [1]: return '', 304
The comparison must be done with the exact ETag string value, not headers from request or response objects.
Fill both blanks to generate an ETag from the content and check the client's ETag.
import hashlib content = b"Hello World" etag = [1](content).hexdigest() if request.headers.get('If-None-Match') == [2]: return '', 304
We use hashlib.md5 to create a hash of the content as the ETag, then compare it to the client's 'If-None-Match' header stored in the variable etag.
Fill all three blanks to set the ETag header, check the client's ETag, and return 304 if they match.
import hashlib content = b"Data to cache" etag = [1](content).hexdigest() response.headers['ETag'] = [2] if request.headers.get('If-None-Match') == [3]: return '', 304
We generate the ETag using hashlib.md5, assign the etag variable to the response header, and compare the same etag variable to the client's 'If-None-Match' header.