File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ public class CacheControl {
77
77
@ Nullable
78
78
private Duration sMaxAge ;
79
79
80
+ private boolean immutable = false ;
81
+
80
82
81
83
/**
82
84
* Create an empty CacheControl instance.
@@ -320,6 +322,18 @@ public CacheControl staleIfError(Duration staleIfError) {
320
322
return this ;
321
323
}
322
324
325
+ /**
326
+ * Add an "immutable" directive.
327
+ * <p>This directive indicates that the origin server will not update the
328
+ * representation of that resource during the freshness lifetime of the response.
329
+ * @return {@code this}, to facilitate method chaining
330
+ * @see <a href="https://tools.ietf.org/html/rfc8246">rfc8246</a>
331
+ */
332
+ public CacheControl immutable () {
333
+ this .immutable = true ;
334
+ return this ;
335
+ }
336
+
323
337
/**
324
338
* Return the "Cache-Control" header value, if any.
325
339
* @return the header value, or {@code null} if no directive was added
@@ -369,6 +383,9 @@ private String toHeaderValue() {
369
383
if (this .staleWhileRevalidate != null ) {
370
384
appendDirective (headerValue , "stale-while-revalidate=" + this .staleWhileRevalidate .getSeconds ());
371
385
}
386
+ if (this .immutable ) {
387
+ appendDirective (headerValue , "immutable" );
388
+ }
372
389
return headerValue .toString ();
373
390
}
374
391
Original file line number Diff line number Diff line change @@ -101,4 +101,10 @@ public void staleWhileRevalidate_duration() throws Exception {
101
101
assertThat (cc .getHeaderValue ()).isEqualTo ("max-age=3600, stale-while-revalidate=7200" );
102
102
}
103
103
104
+ @ Test
105
+ public void immutable () throws Exception {
106
+ CacheControl cc = CacheControl .maxAge (Duration .ofHours (1 )).immutable ();
107
+ assertThat (cc .getHeaderValue ()).isEqualTo ("max-age=3600, immutable" );
108
+ }
109
+
104
110
}
You can’t perform that action at this time.
0 commit comments