aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/lib/view_utils.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-07-31 13:20:55 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-07-31 13:20:55 +0200
commit4ad1b29d831633de1430a683c4ad37873007d34c (patch)
tree7b8a14a4a913b1d862da76587e20edcfe6f521f9 /pyaggr3g470r/lib/view_utils.py
parentadding munin probes (diff)
downloadnewspipe-4ad1b29d831633de1430a683c4ad37873007d34c.tar.gz
newspipe-4ad1b29d831633de1430a683c4ad37873007d34c.tar.bz2
newspipe-4ad1b29d831633de1430a683c4ad37873007d34c.zip
redoing the etag matching mechanism
Diffstat (limited to 'pyaggr3g470r/lib/view_utils.py')
-rw-r--r--pyaggr3g470r/lib/view_utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/pyaggr3g470r/lib/view_utils.py b/pyaggr3g470r/lib/view_utils.py
new file mode 100644
index 00000000..fa5e1eec
--- /dev/null
+++ b/pyaggr3g470r/lib/view_utils.py
@@ -0,0 +1,20 @@
+from functools import wraps
+from flask import request, Response, make_response
+from pyaggr3g470r.lib.utils import to_hash
+
+
+def etag_match(func):
+ @wraps(func)
+ def wrapper(*args, **kwargs):
+ response = func(*args, **kwargs)
+ if not type(response) is str:
+ return response
+ etag = to_hash(response)
+ if request.headers.get('if-none-match') == etag:
+ response = Response(status=304, headers={'etag': etag,
+ 'Cache-Control': 'pragma: no-cache'})
+ else:
+ response = make_response(response)
+ response.headers['etag'] = etag
+ return response
+ return wrapper
bgstack15