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
015import org.apache.juneau.http.annotation.*;
016
017/**
018 * Represents a parsed <l>Cache-Control</l> HTTP request header.
019 *
020 * <p>
021 * Used to specify directives that must be obeyed by all caching mechanisms along the request-response chain.
022 *
023 * <h5 class='figure'>Example</h5>
024 * <p class='bcode w800'>
025 *    Cache-Control: no-cache
026 * </p>
027 *
028 * <h5 class='topic'>RFC2616 Specification</h5>
029 *
030 * The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms
031 * along the request/response chain.
032 * The directives specify behavior intended to prevent caches from adversely interfering with the request or response.
033 * These directives typically override the default caching algorithms.
034 * Cache directives are unidirectional in that the presence of a directive in a request does not imply that the same
035 * directive is to be given in the response.
036 *
037 * <p>
038 * Note that HTTP/1.0 caches might not implement Cache-Control and might only implement Pragma: no-cache (see section
039 * 14.32).
040 *
041 * <p>
042 * Cache directives MUST be passed through by a proxy or gateway application, regardless of their significance to that
043 * application, since the directives might be applicable to all recipients along the request/response chain.
044 * It is not possible to specify a cache- directive for a specific cache.
045 *
046 * <p class='bcode w800'>
047 *    Cache-Control   = "Cache-Control" ":" 1#cache-directive
048 *    cache-directive = cache-request-directive
049 *         | cache-response-directive
050 *    cache-request-directive =
051 *           "no-cache"                          ; Section 14.9.1
052 *         | "no-store"                          ; Section 14.9.2
053 *         | "max-age" "=" delta-seconds         ; Section 14.9.3, 14.9.4
054 *         | "max-stale" [ "=" delta-seconds ]   ; Section 14.9.3
055 *         | "min-fresh" "=" delta-seconds       ; Section 14.9.3
056 *         | "no-transform"                      ; Section 14.9.5
057 *         | "only-if-cached"                    ; Section 14.9.4
058 *         | cache-extension                     ; Section 14.9.6
059 *    cache-response-directive =
060 *           "public"                               ; Section 14.9.1
061 *         | "private" [ "=" &lt;"&gt; 1#field-name &lt;"&gt; ] ; Section 14.9.1
062 *         | "no-cache" [ "=" &lt;"&gt; 1#field-name &lt;"&gt; ]; Section 14.9.1
063 *         | "no-store"                             ; Section 14.9.2
064 *         | "no-transform"                         ; Section 14.9.5
065 *         | "must-revalidate"                      ; Section 14.9.4
066 *         | "proxy-revalidate"                     ; Section 14.9.4
067 *         | "max-age" "=" delta-seconds            ; Section 14.9.3
068 *         | "s-maxage" "=" delta-seconds           ; Section 14.9.3
069 *         | cache-extension                        ; Section 14.9.6
070 *    cache-extension = token [ "=" ( token | quoted-string ) ]
071 * </p>
072 *
073 * <p>
074 * When a directive appears without any 1#field-name parameter, the directive applies to the entire request or response.
075 * When such a directive appears with a 1#field-name parameter, it applies only to the named field or fields, and not
076 * to the rest of the request or response. This mechanism supports extensibility; implementations of future versions
077 * of the HTTP protocol might apply these directives to header fields not defined in HTTP/1.1.
078 *
079 * <p>
080 * The cache-control directives can be broken down into these general categories:
081 * <ul>
082 *    <li>Restrictions on what are cacheable; these may only be imposed by the origin server.
083 *    <li>Restrictions on what may be stored by a cache; these may be imposed by either the origin server or the user
084 *       agent.
085 *    <li>Modifications of the basic expiration mechanism; these may be imposed by either the origin server or the
086 *       user agent.
087 *    <li>Controls over cache revalidation and reload; these may only be imposed by a user agent.
088 *    <li>Control over transformation of entities.
089 *    <li>Extensions to the caching system.
090 * </ul>
091 *
092 * <h5 class='section'>See Also:</h5>
093 * <ul class='doctree'>
094 *    <li class='extlink'>{@doc RFC2616}
095 * </ul>
096 */
097@Header("Cache-Control")
098public final class CacheControl extends HeaderString {
099
100   /**
101    * Returns a parsed <code>Cache-Control</code> header.
102    *
103    * @param value The <code>Cache-Control</code> header string.
104    * @return The parsed <code>Cache-Control</code> header, or <jk>null</jk> if the string was null.
105    */
106   public static CacheControl forString(String value) {
107      if (value == null)
108         return null;
109      return new CacheControl(value);
110   }
111
112   private CacheControl(String value) {
113      super(value);
114   }
115}