Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class ResponseCacheManager {

private static final String VARY_WILDCARD = "*";

private static final Pattern CACHE_CONTROL_SPLITTER = Pattern.compile("\\s*,\\s*");

final CacheKeyGenerator cacheKeyGenerator;

final List<AfterCacheExchangeMutator> afterCacheExchangeMutators;
Expand Down Expand Up @@ -195,8 +198,8 @@ private boolean isVaryWildcard(ServerHttpResponse response) {
private boolean isCacheControlAllowed(HttpMessage request) {
HttpHeaders headers = request.getHeaders();
List<String> cacheControlHeader = headers.getOrEmpty(HttpHeaders.CACHE_CONTROL);

return cacheControlHeader.stream().noneMatch(forbiddenCacheControlValues::contains);
return cacheControlHeader.stream().flatMap(CACHE_CONTROL_SPLITTER::splitAsStream)
.noneMatch(forbiddenCacheControlValues::contains);
}

private static boolean hasRequestBody(ServerHttpRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ void responseShouldNotBeCacheable() {
response.setStatusCode(HttpStatus.OK);

assertThat(cacheManagerToTest.isResponseCacheable(response)).isFalse();

headers = new HttpHeaders();
headers.add(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, max-age=0, must-revalidate");
response = new MockServerHttpResponse();
response.getHeaders().putAll(headers);
response.setStatusCode(HttpStatus.OK);

assertThat(cacheManagerToTest.isResponseCacheable(response)).isFalse();
}

}
Loading