blob: fa5e1eec5cd4bb40333dc21707dd4b9620dc2983 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
|