]> git.ipfire.org Git - people/shoehn/ipfire.org.git/commitdiff
i-use: Send expiry headers
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Apr 2015 09:06:18 +0000 (11:06 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Apr 2015 09:06:18 +0000 (11:06 +0200)
webapp/handlers_iuse.py

index b93552451864924f7467f96bb5d2432c8f401ef4..4fce56d8926a760b792ceb64a9d35a0cf5d36900 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import datetime
 import logging
 import os
 import random
@@ -9,6 +10,8 @@ from handlers_base import *
 import backend
 
 class IUseImage(BaseHandler):
+       expires = 3600 * 3
+
        def write_error(self, status_code, **kwargs):
                """
                        Select a random image from the errors directory
@@ -61,8 +64,14 @@ class IUseImage(BaseHandler):
                        # Render the image
                        image = image_cls(self.backend, self, profile).to_string()
 
-                       # Save the image to the memcache for 60 minutes
-                       self.memcached.set(mem_id, image, 3600)
+                       # Save the image to the memcache
+                       self.memcached.set(mem_id, image, self.expires)
 
                self.set_header("Content-Type", "image/png")
+
+               # Set expiry headers
+               self.set_header("Expires",
+                       datetime.datetime.utcnow() + datetime.timedelta(seconds=self.expires))
+               self.set_header("Cache-Control", "public,max-age=%d" % self.expires)
+
                self.write(image)