Skip to content

Commit 930186e

Browse files
committed
Merge branch '2.1.x'
2 parents dfb2e8a + 00b2954 commit 930186e

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ public CacheControl toHttpCacheControl() {
476476
.staleIfError(duration.getSeconds(), TimeUnit.SECONDS));
477477
map.from(this::getSMaxAge).whenNonNull().to((duration) -> control
478478
.sMaxAge(duration.getSeconds(), TimeUnit.SECONDS));
479+
// check if cacheControl remained untouched
480+
if (control.getHeaderValue() == null) {
481+
return null;
482+
}
479483
return control;
480484
}
481485

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void customStaticLocationsAreNormalizedToEndWithTrailingSlash() {
7676
public void emptyCacheControl() {
7777
CacheControl cacheControl = this.properties.getCache().getCachecontrol()
7878
.toHttpCacheControl();
79-
assertThat(cacheControl.getHeaderValue()).isNull();
79+
assertThat(cacheControl).isNull();
8080
}
8181

8282
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,12 @@ private void assertCachePeriod(AssertableWebApplicationContext context) {
803803
Map<String, Object> handlerMap = getHandlerMap(
804804
context.getBean("resourceHandlerMapping", HandlerMapping.class));
805805
assertThat(handlerMap).hasSize(2);
806-
for (Object handler : handlerMap.keySet()) {
806+
for (Object handler : handlerMap.values()) {
807807
if (handler instanceof ResourceHttpRequestHandler) {
808808
assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds())
809-
.isEqualTo(-1);
809+
.isEqualTo(5);
810810
assertThat(((ResourceHttpRequestHandler) handler).getCacheControl())
811-
.isEqualToComparingFieldByField(
812-
CacheControl.maxAge(5, TimeUnit.SECONDS));
811+
.isNull();
813812
}
814813
}
815814
}

0 commit comments

Comments
 (0)