Complete the code to set the Last-Modified header in the HTTP response.
response.headers['Last-Modified'] = [1]
The Last-Modified header must be set to a valid HTTP date string indicating the last modification time of the resource.
Complete the code to read the If-Modified-Since header from the HTTP request.
last_seen = request.headers.get([1])The If-Modified-Since header is sent by the client to tell the server the last time it saw the resource.
Fix the error in the code that compares If-Modified-Since with Last-Modified to decide if the resource is modified.
if last_modified <= [1]: return 304
You must compare the stored last_modified date with the parsed last_seen date from the If-Modified-Since header.
Fill both blanks to parse the If-Modified-Since header and compare it with the last modified time.
from datetime import datetime client_time = datetime.strptime([1], '%a, %d %b %Y %H:%M:%S GMT') if last_modified <= [2]: return 304
First, get the If-Modified-Since header string, then parse it into a datetime object, and finally compare with last_modified.
Fill all three blanks to set Last-Modified header, parse If-Modified-Since, and return 304 if not modified.
from datetime import datetime last_modified = datetime(2023, 6, 1, 12, 0, 0) response.headers['Last-Modified'] = [1] client_header = request.headers.get('If-Modified-Since') client_time = datetime.strptime([2], '%a, %d %b %Y %H:%M:%S GMT') if client_header else None if client_time and last_modified <= [3]: return 304
Set the Last-Modified header to the correct date string, parse the If-Modified-Since header if present, and compare the datetime objects to decide if 304 should be returned.