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>Vary</l> HTTP response header.
021 *
022 * <p>
023 * Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather
024 * than requesting a fresh one from the origin server.
025 *
026 * <h5 class='figure'>Example</h5>
027 * <p class='bcode'>
028 *    Vary: *
029 *    Vary: Accept-Language
030 * </p>
031 *
032 * <h5 class='topic'>RFC2616 Specification</h5>
033 *
034 * The Vary field value indicates the set of request-header fields that fully determines, while the response is fresh,
035 * whether a cache is permitted to use the response to reply to a subsequent request without revalidation.
036 * For uncacheable or stale responses, the Vary field value advises the user agent about the criteria that were used to
037 * select the representation.
038 * A Vary field value of "*" implies that a cache cannot determine from the request headers of a subsequent request
039 * whether this response is the appropriate representation.
040 * See section 13.6 for use of the Vary header field by caches.
041 * <p class='bcode'>
042 *    Vary  = "Vary" ":" ( "*" | 1#field-name )
043 * </p>
044 *
045 * <p>
046 * An HTTP/1.1 server SHOULD include a Vary header field with any cacheable response that is subject to server-driven
047 * negotiation.
048 * Doing so allows a cache to properly interpret future requests on that resource and informs the user agent about the
049 * presence of negotiation on that resource.
050 * A server MAY include a Vary header field with a non-cacheable response that is subject to server-driven negotiation,
051 * since this might provide the user agent with useful information about the dimensions over which the response varies
052 * at the time of the response.
053 *
054 * <p>
055 * A Vary field value consisting of a list of field-names signals that the representation selected for the response is
056 * based on a selection algorithm which considers ONLY the listed request-header field values in selecting the most
057 * appropriate representation.
058 * A cache MAY assume that the same selection will be made for future requests with the same values for the listed
059 * field names, for the duration of time for which the response is fresh.
060 *
061 * <p>
062 * The field-names given are not limited to the set of standard request-header fields defined by this specification.
063 * Field names are case-insensitive.
064 *
065 * <p>
066 * A Vary field value of "*" signals that unspecified parameters not limited to the request-headers (e.g., the network
067 * address of the client), play a role in the selection of the response representation.
068 * The "*" value MUST NOT be generated by a proxy server; it may only be generated by an origin server.
069 *
070 * <h5 class='section'>See Also:</h5><ul>
071 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
072 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
073 * </ul>
074 *
075 * @serial exclude
076 */
077@Header("Vary")
078public class Vary extends BasicStringHeader {
079
080   //-----------------------------------------------------------------------------------------------------------------
081   // Static
082   //-----------------------------------------------------------------------------------------------------------------
083
084   private static final long serialVersionUID = 1L;
085   private static final String NAME = "Vary";
086
087   /**
088    * Static creator.
089    *
090    * @param value
091    *    The header value.
092    *    <br>Can be <jk>null</jk>.
093    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
094    */
095   public static Vary of(String value) {
096      return value == null ? null : new Vary(value);
097   }
098
099   /**
100    * Static creator with delayed value.
101    *
102    * <p>
103    * Header value is re-evaluated on each call to {@link #getValue()}.
104    *
105    * @param value
106    *    The supplier of the header value.
107    *    <br>Can be <jk>null</jk>.
108    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
109    */
110   public static Vary of(Supplier<String> value) {
111      return value == null ? null : new Vary(value);
112   }
113
114   //-----------------------------------------------------------------------------------------------------------------
115   // Instance
116   //-----------------------------------------------------------------------------------------------------------------
117
118   /**
119    * Constructor.
120    *
121    * @param value
122    *    The header value.
123    *    <br>Can be <jk>null</jk>.
124    */
125   public Vary(String value) {
126      super(NAME, value);
127   }
128
129   /**
130    * Constructor with delayed value.
131    *
132    * <p>
133    * Header value is re-evaluated on each call to {@link #getValue()}.
134    *
135    * @param value
136    *    The supplier of the header value.
137    *    <br>Can be <jk>null</jk>.
138    */
139   public Vary(Supplier<String> value) {
140      super(NAME, value);
141   }
142}