mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Add Cache-Control must-understand directive
Signed-off-by: heka1024 <heka1024@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user