Skip to content

Commit

Permalink
Remove EXPIRES HTTP header from cache
Browse files Browse the repository at this point in the history
This header conflicts and can cause confusion when 'Cache-Control + max-age'
are set. And currently SCG always sets 'max-age' in 'Cache-Control' via
'SetMaxAgeHeaderAfterCacheExchangeMutator'.
  • Loading branch information
abelsromero committed Sep 5, 2024
1 parent 3835adc commit d4143f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ResponseCacheManager(CacheKeyGenerator cacheKeyGenerator, Cache cache, Du
this.ignoreNoCacheUpdate = isSkipNoCacheUpdateActive(requestOptions);
this.afterCacheExchangeMutators = List.of(new SetResponseHeadersAfterCacheExchangeMutator(),
new SetStatusCodeAfterCacheExchangeMutator(),
new RemoveHeadersAfterCacheExchangeMutator(HttpHeaders.PRAGMA),
new RemoveHeadersAfterCacheExchangeMutator(HttpHeaders.PRAGMA, HttpHeaders.EXPIRES),
new SetMaxAgeHeaderAfterCacheExchangeMutator(configuredTimeToLive, Clock.systemDefaultZone(),
ignoreNoCacheUpdate),
new SetCacheDirectivesByMaxAgeAfterCacheExchangeMutator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,30 @@ void shouldNotCacheWhenAuthorizationHeaderIsDifferent() {

@Test
void shouldNotReturnPragmaHeaderInNonCachedAndCachedResponses() {
shouldNotReturnHeader(HttpHeaders.PRAGMA);
}

@Test
void shouldNotReturnExpiresHeaderInNonCachedAndCachedResponses() {
shouldNotReturnHeader(HttpHeaders.EXPIRES);
}

private void shouldNotReturnHeader(String header) {
String uri = "/" + UUID.randomUUID() + "/cache/headers";

testClient.get()
.uri(uri)
.header("Host", "www.localresponsecache.org")
.exchange()
.expectHeader()
.doesNotExist(HttpHeaders.PRAGMA);
.doesNotExist(header);

testClient.get()
.uri(uri)
.header("Host", "www.localresponsecache.org")
.exchange()
.expectHeader()
.doesNotExist(HttpHeaders.PRAGMA);
.doesNotExist(header);
}

void assertNonVaryHeaderInContent(String uri, String varyHeader, String varyHeaderValue, String nonVaryHeader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,30 @@ void shouldGlobalCacheResponseWhenRouteDoesNotHaveFilter() {

@Test
void shouldNotReturnPragmaHeaderInNonCachedAndCachedResponses() {
shouldNotReturnHeader(HttpHeaders.PRAGMA);
}

@Test
void shouldNotReturnExpiresHeaderInNonCachedAndCachedResponses() {
shouldNotReturnHeader(HttpHeaders.EXPIRES);
}

private void shouldNotReturnHeader(String header) {
String uri = "/" + UUID.randomUUID() + "/global-cache/headers";

testClient.get()
.uri(uri)
.header("Host", "www.localresponsecache.org")
.exchange()
.expectHeader()
.doesNotExist(HttpHeaders.PRAGMA);
.doesNotExist(header);

testClient.get()
.uri(uri)
.header("Host", "www.localresponsecache.org")
.exchange()
.expectHeader()
.doesNotExist(HttpHeaders.PRAGMA);
.doesNotExist(header);
}

@EnableAutoConfiguration
Expand Down

0 comments on commit d4143f8

Please sign in to comment.