diff options
author | Adnan Umer <u.adnan@outlook.com> | 2019-08-14 01:40:09 +0500 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-16 15:25:42 +0200 |
commit | 6805c0f99f4790f28a97d597934d0877ba81dba9 (patch) | |
tree | 8e5eeb7d00e197e41943b48f6bacec51100b7539 /django/utils/cache.py | |
parent | 7da6a28a447dc0db2a2c6ef31894094eb968f408 (diff) | |
download | django-6805c0f99f4790f28a97d597934d0877ba81dba9.tar.gz |
Fixed #30701 -- Updated patch_vary_headers() to handle an asterisk according to RFC 7231.
Diffstat (limited to 'django/utils/cache.py')
-rw-r--r-- | django/utils/cache.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index a804604642..2b37acfd44 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -256,8 +256,9 @@ def add_never_cache_headers(response): def patch_vary_headers(response, newheaders): """ Add (or update) the "Vary" header in the given HttpResponse object. - newheaders is a list of header names that should be in "Vary". Existing - headers in "Vary" aren't removed. + newheaders is a list of header names that should be in "Vary". If headers + contains an asterisk, then "Vary" header will consist of a single asterisk + '*'. Otherwise, existing headers in "Vary" aren't removed. """ # Note that we need to keep the original order intact, because cache # implementations may rely on the order of the Vary contents in, say, @@ -270,7 +271,11 @@ def patch_vary_headers(response, newheaders): existing_headers = {header.lower() for header in vary_headers} additional_headers = [newheader for newheader in newheaders if newheader.lower() not in existing_headers] - response['Vary'] = ', '.join(vary_headers + additional_headers) + vary_headers += additional_headers + if '*' in vary_headers: + response['Vary'] = '*' + else: + response['Vary'] = ', '.join(vary_headers) def has_vary_header(response, header_query): |