Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RFC5861 Cache-Control headers #2949

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions src/werkzeug/datastructures/cache_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class ResponseCacheControl(_CacheControl):
s_maxage = cache_control_property("s-maxage", None, int)
immutable = cache_control_property("immutable", None, bool)
must_understand = cache_control_property("must-understand", None, bool)
stale_while_revalidate = cache_control_property("stale-while-revalidate", None, int)
stale_if_error = cache_control_property("stale-if-error", None, int)


# circular dependencies
Expand Down
12 changes: 12 additions & 0 deletions src/werkzeug/datastructures/cache_control.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ class ResponseCacheControl(_CacheControl):
def must_understand(self, value: bool | None) -> None: ...
@must_understand.deleter
def must_understand(self) -> None: ...
@property
def stale_while_revalidate(self) -> int | None: ...
@stale_while_revalidate.setter
def stale_while_revalidate(self, value: int | None) -> None: ...
@stale_while_revalidate.deleter
def stale_while_revalidate(self) -> None: ...
@property
def stale_if_error(self) -> int | None: ...
@stale_if_error.setter
def stale_if_error(self, value: int | None) -> None: ...
@stale_if_error.deleter
def stale_if_error(self) -> None: ...
12 changes: 12 additions & 0 deletions tests/test_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,18 @@ def test_must_understand(self):
cc = ds.ResponseCacheControl()
assert cc.must_understand is False

def test_stale_while_revalidate(self):
cc = ds.ResponseCacheControl([("stale-while-revalidate", "1")])
assert cc.stale_while_revalidate == 1
cc = ds.ResponseCacheControl()
assert cc.stale_while_revalidate is None

def test_stale_if_error(self):
cc = ds.ResponseCacheControl([("stale-if-error", "1")])
assert cc.stale_if_error == 1
cc = ds.ResponseCacheControl()
assert cc.stale_while_revalidate is None


class TestContentSecurityPolicy:
def test_construct(self):
Expand Down