Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def patch_cache_control(response, **kwargs):
are converted to hyphens.
* If the value of a parameter is True (exactly True, not just a
true value), only the parameter name is added to the header.
* For `no-cache` directive if the value of a parameter is Falsy (casts to False),
parameter name is excluded from the header
* All other parameters are added with their value, after applying
str() to it.
"""
Expand Down Expand Up @@ -84,7 +86,8 @@ def dictvalue(*t):
directive = k.replace("_", "-")
if directive == "no-cache":
# no-cache supports multiple field names.
cc[directive].add(v)
if bool(v) is not False:
cc[directive].add(v)
else:
cc[directive] = v

Expand Down
8 changes: 8 additions & 0 deletions tests/cache/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,9 +2107,17 @@ def test_patch_cache_control(self):
(None, {"private": True}, {"private"}),
("", {"private": True}, {"private"}),
# no-cache.
("", {"no_cache": "False"}, {"no-cache=False"}),
("", {"no-cache": False}, {""}),
("", {"no-cache": None}, {""}),
("", {"no-cache": ()}, {""}),
("", {"no-cache": set()}, {""}),
("", {"no-cache": 0}, {""}),
("", {"no-cache": "0"}, {"no-cache=0"}),
("", {"no_cache": "Set-Cookie"}, {"no-cache=Set-Cookie"}),
("", {"no-cache": "Set-Cookie"}, {"no-cache=Set-Cookie"}),
("no-cache=Set-Cookie", {"no_cache": True}, {"no-cache"}),
("no-cache=Set-Cookie", {"no_cache": False}, {"no-cache=Set-Cookie"}),
("no-cache=Set-Cookie,no-cache=Link", {"no_cache": True}, {"no-cache"}),
(
"no-cache=Set-Cookie",
Expand Down