Add Expires header to favicon controller responses

master
Dustin C. Hatch 2012-11-19 17:30:13 -06:00
parent dd05d95dba
commit 5529b66a57
1 changed files with 8 additions and 1 deletions

View File

@ -23,7 +23,8 @@ from one or more of these classes can make things significantly easier.
:Updater: $Author$
'''
import milla
import datetime
import milla.util
import pkg_resources
@ -53,6 +54,9 @@ class FaviconController(Controller):
used as the favicon, defaults to 'image/x-icon' (Windows ICO format)
'''
#: Number of days in the future to set the cache expiration for the icon
EXPIRY_DAYS = 365
def __init__(self, icon=None, content_type='image/x-icon'):
if icon:
try:
@ -72,4 +76,7 @@ class FaviconController(Controller):
response = milla.Response()
response.app_iter = self.icon
response.headers['Content-Type'] = self.content_type
expires = (datetime.datetime.utcnow() +
datetime.timedelta(days=self.EXPIRY_DAYS))
response.headers['Expires'] = milla.util.http_date(expires)
return response