Skip to content

Commit ca8223a

Browse files
committed
Fix: invalid Cache-Control directives for REST package
1. There was a typo on the `must-revalidate` directive (missing dash) 2. The `Cache-Control` header didn't completely prevent HTTP caching 3. The `Last-Modified` header is advantageously replaced by right `Expires` and `Cache-Control` headers
1 parent 4700454 commit ca8223a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

rest/jersey2/src/main/java/org/seedstack/seed/rest/jersey2/internal/CacheControlFeature.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ public void filter(ContainerRequestContext requestContext,
6363
switch (this.policy) {
6464
case NO_CACHE:
6565
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
66-
headers.putSingle(HttpHeaders.LAST_MODIFIED, new Date());
67-
headers.putSingle(HttpHeaders.EXPIRES, -1);
68-
headers.putSingle(HttpHeaders.CACHE_CONTROL, MUST_REVALIDATE_PRIVATE);
66+
67+
// HTTP Caching is a tough subject thanks to the diversity of clients (browser and cache/proxy servers)
68+
// See below a pretty good reference on HTTP Caching:
69+
// https://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
70+
71+
// For client that doesn't support newer `Cache-Control` HTTP header
72+
// https://tools.ietf.org/html/rfc7234#section-5.3
73+
headers.putSingle(HttpHeaders.EXPIRES, 0);
74+
75+
// https://tools.ietf.org/html/rfc7234#section-5.2.2
76+
// Theoretically, `no-store` only would be sufficient
77+
// But for compatibility-purpose, adding other related headers doesn't hurt
78+
headers.putSingle(HttpHeaders.CACHE_CONTROL, "no-store, no-cache, must-revalidate, private");
6979
break;
7080
case CUSTOM:
7181
break;

0 commit comments

Comments
 (0)