|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -569,20 +569,32 @@ public void setSMaxAge(Duration sMaxAge) {
|
569 | 569 | public CacheControl toHttpCacheControl() {
|
570 | 570 | PropertyMapper map = PropertyMapper.get();
|
571 | 571 | 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) |
578 | 588 | .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) |
581 | 592 | .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) |
584 | 596 | .whenNonNull()
|
585 |
| - .to((duration) -> control.sMaxAge(duration.getSeconds(), TimeUnit.SECONDS)); |
| 597 | + .to(control, (instance, duration) -> instance.sMaxAge(duration.getSeconds(), TimeUnit.SECONDS)); |
586 | 598 | // check if cacheControl remained untouched
|
587 | 599 | if (control.getHeaderValue() == null) {
|
588 | 600 | return null;
|
|
0 commit comments