Add Cache-Control must-understand directive

Signed-off-by: heka1024 <heka1024@gmail.com>
This commit is contained in:
heka1024
2026-08-28 15:10:37 +02:00
committed by Brian Clozel
parent 2588fb078e
commit d9e240b37d
2 changed files with 25 additions and 0 deletions
@@ -58,6 +58,8 @@ public class CacheControl {
private boolean noStore = false;
private boolean mustUnderstand = false;
private boolean mustRevalidate = false;
private boolean noTransform = false;
@@ -165,6 +167,20 @@ public class CacheControl {
return cc;
}
/**
* Add a "must-understand" directive.
* <p>This directive limits caching of the response to caches that
* understand and conform to the requirements for the response status code.
* The {@link #noStore()} directive should also be set as a fallback for
* caches that do not implement the "must-understand" directive.
* @return {@code this}, to facilitate method chaining
* @since 7.1
* @see <a href="https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.3">rfc9111 section 5.2.2.3</a>
*/
public CacheControl mustUnderstand() {
this.mustUnderstand = true;
return this;
}
/**
* Add a "must-revalidate" directive.
@@ -358,6 +374,9 @@ public class CacheControl {
if (this.noStore) {
appendDirective(headerValue, "no-store");
}
if (this.mustUnderstand) {
appendDirective(headerValue, "must-understand");
}
if (this.mustRevalidate) {
appendDirective(headerValue, "must-revalidate");
}
@@ -78,6 +78,12 @@ class CacheControlTests {
assertThat(cc.getHeaderValue()).isEqualTo("no-store");
}
@Test
void mustUnderstand() {
CacheControl cc = CacheControl.noStore().mustUnderstand();
assertThat(cc.getHeaderValue()).isEqualTo("no-store, must-understand");
}
@Test
void staleIfError() {
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS).staleIfError(2, TimeUnit.HOURS);