Skip to content

Commit 7343254

Browse files
committed
Adapt to framework change that makes CacheControl immutable
See spring-projects/spring-framework#33366
1 parent 6031d04 commit 7343254

File tree

1 file changed

+24
-12
lines changed
  • spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web

1 file changed

+24
-12
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -569,20 +569,32 @@ public void setSMaxAge(Duration sMaxAge) {
569569
public CacheControl toHttpCacheControl() {
570570
PropertyMapper map = PropertyMapper.get();
571571
CacheControl control = createCacheControl();
572-
map.from(this::getMustRevalidate).whenTrue().toCall(control::mustRevalidate);
573-
map.from(this::getNoTransform).whenTrue().toCall(control::noTransform);
574-
map.from(this::getCachePublic).whenTrue().toCall(control::cachePublic);
575-
map.from(this::getCachePrivate).whenTrue().toCall(control::cachePrivate);
576-
map.from(this::getProxyRevalidate).whenTrue().toCall(control::proxyRevalidate);
577-
map.from(this::getStaleWhileRevalidate)
572+
if (Boolean.TRUE.equals(this.mustRevalidate)) {
573+
control = control.mustRevalidate();
574+
}
575+
if (Boolean.TRUE.equals(this.noTransform)) {
576+
control = control.noTransform();
577+
}
578+
if (Boolean.TRUE.equals(this.cachePrivate)) {
579+
control = control.cachePrivate();
580+
}
581+
if (Boolean.TRUE.equals(this.cachePublic)) {
582+
control = control.cachePublic();
583+
}
584+
if (Boolean.TRUE.equals(this.proxyRevalidate)) {
585+
control = control.proxyRevalidate();
586+
}
587+
control = map.from(this::getStaleWhileRevalidate)
578588
.whenNonNull()
579-
.to((duration) -> control.staleWhileRevalidate(duration.getSeconds(), TimeUnit.SECONDS));
580-
map.from(this::getStaleIfError)
589+
.to(control, (instance, duration) -> instance.staleWhileRevalidate(duration.getSeconds(),
590+
TimeUnit.SECONDS));
591+
control = map.from(this::getStaleIfError)
581592
.whenNonNull()
582-
.to((duration) -> control.staleIfError(duration.getSeconds(), TimeUnit.SECONDS));
583-
map.from(this::getSMaxAge)
593+
.to(control,
594+
(instance, duration) -> instance.staleIfError(duration.getSeconds(), TimeUnit.SECONDS));
595+
control = map.from(this::getSMaxAge)
584596
.whenNonNull()
585-
.to((duration) -> control.sMaxAge(duration.getSeconds(), TimeUnit.SECONDS));
597+
.to(control, (instance, duration) -> instance.sMaxAge(duration.getSeconds(), TimeUnit.SECONDS));
586598
// check if cacheControl remained untouched
587599
if (control.getHeaderValue() == null) {
588600
return null;

0 commit comments

Comments
 (0)