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.header;
014
015import java.util.function.*;
016
017import org.apache.juneau.http.annotation.*;
018
019/**
020 * Represents a parsed <l>Pragma</l> HTTP request/response header.
021 *
022 * <p>
023 * Implementation-specific fields that may have various effects anywhere along the request-response chain.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode w800'>
027 *    Pragma: no-cache
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The Pragma general-header field is used to include implementation- specific directives that might apply to any
033 * recipient along the request/response chain.
034 * All pragma directives specify optional behavior from the viewpoint of the protocol; however, some systems MAY
035 * require that behavior be consistent with the directives.
036 *
037 * <p class='bcode w800'>
038 *    Pragma            = "Pragma" ":" 1#pragma-directive
039 *    pragma-directive  = "no-cache" | extension-pragma
040 *    extension-pragma  = token [ "=" ( token | quoted-string ) ]
041 * </p>
042 *
043 * <p>
044 * When the no-cache directive is present in a request message, an application SHOULD forward the request toward the
045 * origin server even if it has a cached copy of what is being requested.
046 * This pragma directive has the same semantics as the no-cache cache-directive (see section 14.9) and is defined here
047 * for backward compatibility with HTTP/1.0.
048 * Clients SHOULD include both header fields when a no-cache request is sent to a server not known to be HTTP/1.1
049 * compliant.
050 *
051 * <p>
052 * Pragma directives MUST be passed through by a proxy or gateway application, regardless of their significance to that
053 * application, since the directives might be applicable to all recipients along the request/response chain.
054 * It is not possible to specify a pragma for a specific recipient; however, any pragma directive not relevant to a
055 * recipient SHOULD be ignored by that recipient.
056 *
057 * <p>
058 * HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client had sent "Cache-Control: no-cache".
059 * No new Pragma directives will be defined in HTTP.
060 *
061 * <p>
062 * Note: because the meaning of "Pragma: no-cache as a response header field is not actually specified, it does not
063 * provide a reliable replacement for "Cache-Control: no-cache" in a response.
064 *
065 * <ul class='seealso'>
066 *    <li class='extlink'>{@doc ExtRFC2616}
067 * </ul>
068 */
069@Header("Pragma")
070public class Pragma extends BasicStringHeader {
071
072   private static final long serialVersionUID = 1L;
073
074   /**
075    * Convenience creator.
076    *
077    * @param value
078    *    The header value.
079    *    <br>Can be any of the following:
080    *    <ul>
081    *       <li>{@link String}
082    *       <li>Anything else - Converted to <c>String</c> then parsed.
083    *    </ul>
084    * @return A new {@link Pragma} object.
085    */
086   public static Pragma of(Object value) {
087      if (value == null)
088         return null;
089      return new Pragma(value);
090   }
091
092   /**
093    * Convenience creator using supplier.
094    *
095    * <p>
096    * Header value is re-evaluated on each call to {@link #getValue()}.
097    *
098    * @param value
099    *    The header value supplier.
100    *    <br>Can be any of the following:
101    *    <ul>
102    *       <li>{@link String}
103    *       <li>Anything else - Converted to <c>String</c> then parsed.
104    *    </ul>
105    * @return A new {@link Pragma} object.
106    */
107   public static Pragma of(Supplier<?> value) {
108      if (value == null)
109         return null;
110      return new Pragma(value);
111   }
112
113   /**
114    * Constructor.
115    *
116    * @param value
117    *    The header value.
118    *    <br>Can be any of the following:
119    *    <ul>
120    *       <li>{@link String}
121    *       <li>Anything else - Converted to <c>String</c> then parsed.
122    *       <li>A {@link Supplier} of anything on this list.
123    *    </ul>
124    */
125   public Pragma(Object value) {
126      super("Pragma", value);
127   }
128
129   /**
130    * Constructor
131    *
132    * @param value
133    *    The header value.
134    */
135   public Pragma(String value) {
136      this((Object)value);
137   }
138}