From: Michael Tremer Date: Tue, 28 Apr 2015 09:06:18 +0000 (+0200) Subject: i-use: Send expiry headers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7c4018be248cdbfed6668c387ab4160a517b214;p=ipfire.org.git i-use: Send expiry headers --- diff --git a/webapp/handlers_iuse.py b/webapp/handlers_iuse.py index b9355245..4fce56d8 100644 --- a/webapp/handlers_iuse.py +++ b/webapp/handlers_iuse.py @@ -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)