diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2015-12-17 13:05:26 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2015-12-17 13:05:26 +0100 |
commit | 0312e25586d381cc53935c2fd4912378cd292d6e (patch) | |
tree | b04ad1a26edd4c67701d0d704c8ce8c554b2ae42 /src/web/lib/view_utils.py | |
parent | Updated link to Heroku deploy button on the About page. (diff) | |
parent | handling failing feed link (diff) | |
download | newspipe-0312e25586d381cc53935c2fd4912378cd292d6e.tar.gz newspipe-0312e25586d381cc53935c2fd4912378cd292d6e.tar.bz2 newspipe-0312e25586d381cc53935c2fd4912378cd292d6e.zip |
Merge pull request #24 from jaesivsm/master
moving the root of source code from / to /src/
Diffstat (limited to 'src/web/lib/view_utils.py')
-rw-r--r-- | src/web/lib/view_utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/web/lib/view_utils.py b/src/web/lib/view_utils.py new file mode 100644 index 00000000..d4c119da --- /dev/null +++ b/src/web/lib/view_utils.py @@ -0,0 +1,26 @@ +from functools import wraps +from flask import request, Response, make_response +from web.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 |