summaryrefslogtreecommitdiff
path: root/webapp.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2013-02-22 18:33:22 +0100
committerHelmut Grohne <helmut@subdivi.de>2013-02-22 18:33:22 +0100
commit5c8de0beba593aaee874d2651131a2cf2135f33c (patch)
tree81ef7a27aeed0cf03683af7298d41b7cdce38fc6 /webapp.py
parent6809c8fab03c5e4d73c375eba3b7557509a565b6 (diff)
downloaddebian-dedup-5c8de0beba593aaee874d2651131a2cf2135f33c.tar.gz
webapp: add caching headers
Diffstat (limited to 'webapp.py')
-rwxr-xr-xwebapp.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/webapp.py b/webapp.py
index de41aa1..dc09ea7 100755
--- a/webapp.py
+++ b/webapp.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
+import datetime
import sqlite3
from wsgiref.simple_server import make_server
@@ -111,8 +112,11 @@ def encode_and_buffer(iterator):
if buff:
yield buff
-def html_response(unicode_iterator):
- return Response(encode_and_buffer(unicode_iterator), mimetype="text/html")
+def html_response(unicode_iterator, max_age=24 * 60 * 60):
+ resp = Response(encode_and_buffer(unicode_iterator), mimetype="text/html")
+ resp.cache_control.max_age = max_age
+ resp.expires = datetime.datetime.now() + datetime.timedelta(seconds=max_age)
+ return resp
class Application(object):
def __init__(self):