diff options
author | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-08-03 23:55:46 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-08-03 23:55:46 +0200 |
commit | cdbd573500a365e290e88b50d7b0c2355b7f7e19 (patch) | |
tree | 25ede52ae4b02a2377ae40d2c146c7ed2e9abe2a /pyaggr3g470r/lib/view_utils.py | |
parent | The numver ov values of the splited string is variable (sometimes the charset... (diff) | |
parent | sqlalchemy was requesting icons everytime feed where listed (diff) | |
download | newspipe-cdbd573500a365e290e88b50d7b0c2355b7f7e19.tar.gz newspipe-cdbd573500a365e290e88b50d7b0c2355b7f7e19.tar.bz2 newspipe-cdbd573500a365e290e88b50d7b0c2355b7f7e19.zip |
Merged in jaesivsm/pyaggr3g470r (pull request #20)
perf improvement
Diffstat (limited to 'pyaggr3g470r/lib/view_utils.py')
-rw-r--r-- | pyaggr3g470r/lib/view_utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pyaggr3g470r/lib/view_utils.py b/pyaggr3g470r/lib/view_utils.py new file mode 100644 index 00000000..0cfe62c4 --- /dev/null +++ b/pyaggr3g470r/lib/view_utils.py @@ -0,0 +1,26 @@ +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 isinstance(response, Response): + etag = to_hash(response.data) + headers = response.headers + elif type(response) is str: + etag = to_hash(response) + headers = {} + else: + return response + if request.headers.get('if-none-match') == etag: + response = Response(status=304) + response.headers['Cache-Control'] \ + = headers.get('Cache-Control', 'pragma: no-cache') + elif not isinstance(response, Response): + response = make_response(response) + response.headers['etag'] = etag + return response + return wrapper |