equal
deleted
inserted
replaced
1 try: |
1 try: |
2 from functools import wraps |
2 from functools import wraps |
3 except ImportError: |
3 except ImportError: |
4 from django.utils.functional import wraps # Python 2.3, 2.4 fallback. |
4 from django.utils.functional import wraps # Python 2.4 fallback. |
5 |
5 |
6 from django.utils.cache import patch_vary_headers |
6 from django.utils.cache import patch_vary_headers |
|
7 from django.utils.decorators import available_attrs |
7 |
8 |
8 def vary_on_headers(*headers): |
9 def vary_on_headers(*headers): |
9 """ |
10 """ |
10 A view decorator that adds the specified headers to the Vary header of the |
11 A view decorator that adds the specified headers to the Vary header of the |
11 response. Usage: |
12 response. Usage: |
19 def decorator(func): |
20 def decorator(func): |
20 def inner_func(*args, **kwargs): |
21 def inner_func(*args, **kwargs): |
21 response = func(*args, **kwargs) |
22 response = func(*args, **kwargs) |
22 patch_vary_headers(response, headers) |
23 patch_vary_headers(response, headers) |
23 return response |
24 return response |
24 return wraps(func)(inner_func) |
25 return wraps(func, assigned=available_attrs(func))(inner_func) |
25 return decorator |
26 return decorator |
26 |
27 |
27 def vary_on_cookie(func): |
28 def vary_on_cookie(func): |
28 """ |
29 """ |
29 A view decorator that adds "Cookie" to the Vary header of a response. This |
30 A view decorator that adds "Cookie" to the Vary header of a response. This |
35 """ |
36 """ |
36 def inner_func(*args, **kwargs): |
37 def inner_func(*args, **kwargs): |
37 response = func(*args, **kwargs) |
38 response = func(*args, **kwargs) |
38 patch_vary_headers(response, ('Cookie',)) |
39 patch_vary_headers(response, ('Cookie',)) |
39 return response |
40 return response |
40 return wraps(func)(inner_func) |
41 return wraps(func, assigned=available_attrs(func))(inner_func) |