blue-png-cachable.py (564B)
1 import os 2 from wptserve.utils import isomorphic_decode 3 4 def main(request, response): 5 """Serves the contents in blue.png but with a Cache-Control header. 6 7 Emits a Cache-Control header with max-age set to 1h to allow the browser 8 cache the image. Used for testing behaviors involving caching logics. 9 """ 10 image_path = os.path.join(os.path.dirname(isomorphic_decode(__file__)), u"blue.png") 11 response.headers.set(b"Cache-Control", b"max-age=3600") 12 response.headers.set(b"Content-Type", b"image/png") 13 response.content = open(image_path, mode='rb').read()