cache.py (575B)
1 ETAG = b'"123abc"' 2 CONTENT_TYPE = b"text/plain" 3 CONTENT = b"lorem ipsum dolor sit amet" 4 5 6 def main(request, response): 7 # let caching kick in if possible (conditional GET) 8 etag = request.headers.get(b"If-None-Match", None) 9 if etag == ETAG: 10 response.headers.set(b"X-HTTP-STATUS", 304) 11 response.status = (304, b"Not Modified") 12 return b"" 13 14 # cache miss, so respond with the actual content 15 response.status = (200, b"OK") 16 response.headers.set(b"ETag", ETAG) 17 response.headers.set(b"Content-Type", CONTENT_TYPE) 18 return CONTENT