|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2002-2016 the original author or authors.
|
|
|
|
|
* Copyright 2002-2018 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
@@ -83,7 +83,8 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return an empty directive.
|
|
|
|
|
* <p>This is well suited for using other optional directives without "max-age", "no-cache" or "no-store".
|
|
|
|
|
* <p>This is well suited for using other optional directives without "max-age",
|
|
|
|
|
* "no-cache" or "no-store".
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
*/
|
|
|
|
|
public static CacheControl empty() {
|
|
|
|
|
@@ -92,11 +93,13 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "max-age=" directive.
|
|
|
|
|
* <p>This directive is well suited for publicly caching resources, knowing that they won't change within
|
|
|
|
|
* the configured amount of time. Additional directives can be also used, in case resources shouldn't be
|
|
|
|
|
* cached ({@link #cachePrivate()}) or transformed ({@link #noTransform()}) by shared caches.
|
|
|
|
|
* <p>In order to prevent caches to reuse the cached response even when it has become stale
|
|
|
|
|
* (i.e. the "max-age" delay is passed), the "must-revalidate" directive should be set ({@link #mustRevalidate()}
|
|
|
|
|
* <p>This directive is well suited for publicly caching resources, knowing that
|
|
|
|
|
* they won't change within the configured amount of time. Additional directives
|
|
|
|
|
* can be also used, in case resources shouldn't be cached ({@link #cachePrivate()})
|
|
|
|
|
* or transformed ({@link #noTransform()}) by shared caches.
|
|
|
|
|
* <p>In order to prevent caches to reuse the cached response even when it has
|
|
|
|
|
* become stale (i.e. the "max-age" delay is passed), the "must-revalidate"
|
|
|
|
|
* directive should be set ({@link #mustRevalidate()}
|
|
|
|
|
* @param maxAge the maximum time the response should be cached
|
|
|
|
|
* @param unit the time unit of the {@code maxAge} argument
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
@@ -110,12 +113,13 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "no-cache" directive.
|
|
|
|
|
* <p>This directive is well suited for telling caches that the response can be reused only if the client
|
|
|
|
|
* revalidates it with the server. This directive won't disable cache altogether and may result with
|
|
|
|
|
* clients sending conditional requests (with "ETag", "If-Modified-Since" headers) and the server responding
|
|
|
|
|
* with "304 - Not Modified" status.
|
|
|
|
|
* <p>In order to disable caching and minimize requests/responses exchanges, the {@link #noStore()} directive
|
|
|
|
|
* should be used instead of {@link #noCache()}.
|
|
|
|
|
* <p>This directive is well suited for telling caches that the response
|
|
|
|
|
* can be reused only if the client revalidates it with the server.
|
|
|
|
|
* This directive won't disable cache altogether and may result with clients
|
|
|
|
|
* sending conditional requests (with "ETag", "If-Modified-Since" headers)
|
|
|
|
|
* and the server responding with "304 - Not Modified" status.
|
|
|
|
|
* <p>In order to disable caching and minimize requests/responses exchanges,
|
|
|
|
|
* the {@link #noStore()} directive should be used instead of {@code #noCache()}.
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.2">rfc7234 section 5.2.2.2</a>
|
|
|
|
|
*/
|
|
|
|
|
@@ -127,7 +131,8 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "no-store" directive.
|
|
|
|
|
* <p>This directive is well suited for preventing caches (browsers and proxies) to cache the content of responses.
|
|
|
|
|
* <p>This directive is well suited for preventing caches (browsers and proxies)
|
|
|
|
|
* to cache the content of responses.
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.3">rfc7234 section 5.2.2.3</a>
|
|
|
|
|
*/
|
|
|
|
|
@@ -140,8 +145,9 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "must-revalidate" directive.
|
|
|
|
|
* <p>This directive indicates that once it has become stale, a cache MUST NOT use the response
|
|
|
|
|
* to satisfy subsequent requests without successful validation on the origin server.
|
|
|
|
|
* <p>This directive indicates that once it has become stale, a cache MUST NOT
|
|
|
|
|
* use the response to satisfy subsequent requests without successful validation
|
|
|
|
|
* on the origin server.
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.1">rfc7234 section 5.2.2.1</a>
|
|
|
|
|
*/
|
|
|
|
|
@@ -152,8 +158,9 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "no-transform" directive.
|
|
|
|
|
* <p>This directive indicates that intermediaries (caches and others) should not transform the response content.
|
|
|
|
|
* This can be useful to force caches and CDNs not to automatically gzip or optimize the response content.
|
|
|
|
|
* <p>This directive indicates that intermediaries (caches and others) should
|
|
|
|
|
* not transform the response content. This can be useful to force caches and
|
|
|
|
|
* CDNs not to automatically gzip or optimize the response content.
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.4">rfc7234 section 5.2.2.4</a>
|
|
|
|
|
*/
|
|
|
|
|
@@ -164,8 +171,9 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "public" directive.
|
|
|
|
|
* <p>This directive indicates that any cache MAY store the response, even if the response
|
|
|
|
|
* would normally be non-cacheable or cacheable only within a private cache.
|
|
|
|
|
* <p>This directive indicates that any cache MAY store the response,
|
|
|
|
|
* even if the response would normally be non-cacheable or cacheable
|
|
|
|
|
* only within a private cache.
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.5">rfc7234 section 5.2.2.5</a>
|
|
|
|
|
*/
|
|
|
|
|
@@ -176,8 +184,8 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "private" directive.
|
|
|
|
|
* <p>This directive indicates that the response message is intended for a single user
|
|
|
|
|
* and MUST NOT be stored by a shared cache.
|
|
|
|
|
* <p>This directive indicates that the response message is intended
|
|
|
|
|
* for a single user and MUST NOT be stored by a shared cache.
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.6">rfc7234 section 5.2.2.6</a>
|
|
|
|
|
*/
|
|
|
|
|
@@ -200,8 +208,8 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add an "s-maxage" directive.
|
|
|
|
|
* <p>This directive indicates that, in shared caches, the maximum age specified by this directive
|
|
|
|
|
* overrides the maximum age specified by other directives.
|
|
|
|
|
* <p>This directive indicates that, in shared caches, the maximum age specified
|
|
|
|
|
* by this directive overrides the maximum age specified by other directives.
|
|
|
|
|
* @param sMaxAge the maximum time the response should be cached
|
|
|
|
|
* @param unit the time unit of the {@code sMaxAge} argument
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
@@ -214,10 +222,11 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "stale-while-revalidate" directive.
|
|
|
|
|
* <p>This directive indicates that caches MAY serve the response in
|
|
|
|
|
* which it appears after it becomes stale, up to the indicated number of seconds.
|
|
|
|
|
* <p>This directive indicates that caches MAY serve the response in which it
|
|
|
|
|
* appears after it becomes stale, up to the indicated number of seconds.
|
|
|
|
|
* If a cached response is served stale due to the presence of this extension,
|
|
|
|
|
* the cache SHOULD attempt to revalidate it while still serving stale responses (i.e., without blocking).
|
|
|
|
|
* the cache SHOULD attempt to revalidate it while still serving stale responses
|
|
|
|
|
* (i.e. without blocking).
|
|
|
|
|
* @param staleWhileRevalidate the maximum time the response should be used while being revalidated
|
|
|
|
|
* @param unit the time unit of the {@code staleWhileRevalidate} argument
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
@@ -230,8 +239,8 @@ public class CacheControl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a "stale-if-error" directive.
|
|
|
|
|
* <p>This directive indicates that when an error is encountered, a cached stale response MAY be used to satisfy
|
|
|
|
|
* the request, regardless of other freshness information.
|
|
|
|
|
* <p>This directive indicates that when an error is encountered, a cached stale response
|
|
|
|
|
* MAY be used to satisfy the request, regardless of other freshness information.
|
|
|
|
|
* @param staleIfError the maximum time the response should be used when errors are encountered
|
|
|
|
|
* @param unit the time unit of the {@code staleIfError} argument
|
|
|
|
|
* @return {@code this}, to facilitate method chaining
|
|
|
|
|
|