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 w800'> 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 w800'> 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 * <ul class='seealso'> 071 * <li class='extlink'>{@doc ExtRFC2616} 072 * </ul> 073 */ 074@Header("Vary") 075public class Vary extends BasicStringHeader { 076 077 private static final long serialVersionUID = 1L; 078 079 /** 080 * Convenience creator. 081 * 082 * @param value 083 * The header value. 084 * <br>Can be any of the following: 085 * <ul> 086 * <li>{@link String} 087 * <li>Anything else - Converted to <c>String</c> then parsed. 088 * </ul> 089 * @return A new {@link Vary} object. 090 */ 091 public static Vary of(Object value) { 092 if (value == null) 093 return null; 094 return new Vary(value); 095 } 096 097 /** 098 * Convenience creator using supplier. 099 * 100 * <p> 101 * Header value is re-evaluated on each call to {@link #getValue()}. 102 * 103 * @param value 104 * The header value supplier. 105 * <br>Can be any of the following: 106 * <ul> 107 * <li>{@link String} 108 * <li>Anything else - Converted to <c>String</c> then parsed. 109 * </ul> 110 * @return A new {@link Vary} object. 111 */ 112 public static Vary of(Supplier<?> value) { 113 if (value == null) 114 return null; 115 return new Vary(value); 116 } 117 118 /** 119 * Constructor. 120 * 121 * @param value 122 * The header value. 123 * <br>Can be any of the following: 124 * <ul> 125 * <li>{@link String} 126 * <li>Anything else - Converted to <c>String</c> then parsed. 127 * <li>A {@link Supplier} of anything on this list. 128 * </ul> 129 */ 130 public Vary(Object value) { 131 super("Vary", value); 132 } 133 134 /** 135 * Constructor 136 * 137 * @param value 138 * The header value. 139 */ 140 public Vary(String value) { 141 this((Object)value); 142 } 143}