MCPcopy
hub / github.com/django/django / vary_on_headers

Function vary_on_headers

django/views/decorators/vary.py:7–36  ·  view source on GitHub ↗

A view decorator that adds the specified headers to the Vary header of the response. Usage: @vary_on_headers('Cookie', 'Accept-language') def index(request): ... Note that the header names are not case-sensitive.

(*headers)

Source from the content-addressed store, hash-verified

5
6
7def vary_on_headers(*headers):
8 """
9 A view decorator that adds the specified headers to the Vary header of the
10 response. Usage:
11
12 @vary_on_headers('Cookie', 'Accept-language')
13 def index(request):
14 ...
15
16 Note that the header names are not case-sensitive.
17 """
18
19 def decorator(func):
20 if iscoroutinefunction(func):
21
22 async def _view_wrapper(request, *args, **kwargs):
23 response = await func(request, *args, **kwargs)
24 patch_vary_headers(response, headers)
25 return response
26
27 else:
28
29 def _view_wrapper(request, *args, **kwargs):
30 response = func(request, *args, **kwargs)
31 patch_vary_headers(response, headers)
32 return response
33
34 return wraps(func)(_view_wrapper)
35
36 return decorator
37
38
39vary_on_cookie = vary_on_headers("Cookie")

Calls

no outgoing calls