mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 13:31:46 +00:00
Polishing CacheControl behavior
This commit builds on the previous commit and ensures that "must-understand" is only used with "no-store". This check is performed at runtime as a staged interface/builder would be a major breaking change for a behavior that is highlighted as "SHOULD" in the specification. This commit also performs similar runtime checks for: * cache-public + cache-private * cache-public + no-store See gh-36918
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
|
||||
/**
|
||||
@@ -84,6 +85,22 @@ class CacheControlTests {
|
||||
assertThat(cc.getHeaderValue()).isEqualTo("no-store, must-understand");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mustUnderstandWithoutNoStoreRejected() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> CacheControl.maxAge(1, TimeUnit.HOURS).mustUnderstand());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cachePublicAndCachePrivateRejected() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> CacheControl.empty().cachePrivate().cachePublic());
|
||||
assertThatIllegalStateException().isThrownBy(() -> CacheControl.empty().cachePublic().cachePrivate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cachePublicWithNoStoreRejected() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> CacheControl.noStore().cachePublic());
|
||||
}
|
||||
|
||||
@Test
|
||||
void staleIfError() {
|
||||
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS).staleIfError(2, TimeUnit.HOURS);
|
||||
|
||||
Reference in New Issue
Block a user