001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http;
014
015/**
016 * Represents a parsed <l>Cache-Control</l> HTTP request header.
017 * 
018 * <p>
019 * Used to specify directives that must be obeyed by all caching mechanisms along the request-response chain.
020 * 
021 * <h5 class='figure'>Example</h5>
022 * <p class='bcode'>
023 *    Cache-Control: no-cache
024 * </p>
025 * 
026 * <h5 class='topic'>RFC2616 Specification</h5>
027 * 
028 * The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms
029 * along the request/response chain.
030 * The directives specify behavior intended to prevent caches from adversely interfering with the request or response.
031 * These directives typically override the default caching algorithms.
032 * Cache directives are unidirectional in that the presence of a directive in a request does not imply that the same
033 * directive is to be given in the response.
034 * 
035 * <p>
036 * Note that HTTP/1.0 caches might not implement Cache-Control and might only implement Pragma: no-cache (see section
037 * 14.32).
038 * 
039 * <p>
040 * Cache directives MUST be passed through by a proxy or gateway application, regardless of their significance to that
041 * application, since the directives might be applicable to all recipients along the request/response chain.
042 * It is not possible to specify a cache- directive for a specific cache.
043 * 
044 * <p class='bcode'>
045 *    Cache-Control   = "Cache-Control" ":" 1#cache-directive
046 *    cache-directive = cache-request-directive
047 *         | cache-response-directive
048 *    cache-request-directive =
049 *           "no-cache"                          ; Section 14.9.1
050 *         | "no-store"                          ; Section 14.9.2
051 *         | "max-age" "=" delta-seconds         ; Section 14.9.3, 14.9.4
052 *         | "max-stale" [ "=" delta-seconds ]   ; Section 14.9.3
053 *         | "min-fresh" "=" delta-seconds       ; Section 14.9.3
054 *         | "no-transform"                      ; Section 14.9.5
055 *         | "only-if-cached"                    ; Section 14.9.4
056 *         | cache-extension                     ; Section 14.9.6
057 *    cache-response-directive =
058 *           "public"                               ; Section 14.9.1
059 *         | "private" [ "=" &lt;"&gt; 1#field-name &lt;"&gt; ] ; Section 14.9.1
060 *         | "no-cache" [ "=" &lt;"&gt; 1#field-name &lt;"&gt; ]; Section 14.9.1
061 *         | "no-store"                             ; Section 14.9.2
062 *         | "no-transform"                         ; Section 14.9.5
063 *         | "must-revalidate"                      ; Section 14.9.4
064 *         | "proxy-revalidate"                     ; Section 14.9.4
065 *         | "max-age" "=" delta-seconds            ; Section 14.9.3
066 *         | "s-maxage" "=" delta-seconds           ; Section 14.9.3
067 *         | cache-extension                        ; Section 14.9.6
068 *    cache-extension = token [ "=" ( token | quoted-string ) ]
069 * </p>
070 * 
071 * <p>
072 * When a directive appears without any 1#field-name parameter, the directive applies to the entire request or response.
073 * When such a directive appears with a 1#field-name parameter, it applies only to the named field or fields, and not
074 * to the rest of the request or response. This mechanism supports extensibility; implementations of future versions
075 * of the HTTP protocol might apply these directives to header fields not defined in HTTP/1.1.
076 * 
077 * <p>
078 * The cache-control directives can be broken down into these general categories:
079 * <ul>
080 *    <li>Restrictions on what are cacheable; these may only be imposed by the origin server.
081 *    <li>Restrictions on what may be stored by a cache; these may be imposed by either the origin server or the user
082 *       agent.
083 *    <li>Modifications of the basic expiration mechanism; these may be imposed by either the origin server or the
084 *       user agent.
085 *    <li>Controls over cache revalidation and reload; these may only be imposed by a user agent.
086 *    <li>Control over transformation of entities.
087 *    <li>Extensions to the caching system.
088 * </ul>
089 * 
090 * <h5 class='section'>See Also:</h5>
091 * <ul class='doctree'>
092 *    <li class='extlink'><a class='doclink' href='https://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a>
093 * </ul>
094 */
095public final class CacheControl extends HeaderString {
096
097   /**
098    * Returns a parsed <code>Cache-Control</code> header.
099    * 
100    * @param value The <code>Cache-Control</code> header string.
101    * @return The parsed <code>Cache-Control</code> header, or <jk>null</jk> if the string was null.
102    */
103   public static CacheControl forString(String value) {
104      if (value == null)
105         return null;
106      return new CacheControl(value);
107   }
108
109   private CacheControl(String value) {
110      super(value);
111   }
112}