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>Warning</l> HTTP request/response header. 021 * 022 * <p> 023 * A general warning about possible problems with the entity body. 024 * 025 * <h5 class='figure'>Example</h5> 026 * <p class='bcode w800'> 027 * Warning: 199 Miscellaneous warning 028 * </p> 029 * 030 * <h5 class='topic'>RFC2616 Specification</h5> 031 * 032 * The Warning general-header field is used to carry additional information about the status or transformation of a 033 * message which might not be reflected in the message. 034 * This information is typically used to warn about a possible lack of semantic transparency from caching operations 035 * or transformations applied to the entity body of the message. 036 * 037 * <p> 038 * Warning headers are sent with responses using: 039 * <p class='bcode w800'> 040 * Warning = "Warning" ":" 1#warning-value 041 * warning-value = warn-code SP warn-agent SP warn-text 042 * [SP warn-date] 043 * warn-code = 3DIGIT 044 * warn-agent = ( host [ ":" port ] ) | pseudonym 045 * ; the name or pseudonym of the server adding 046 * ; the Warning header, for use in debugging 047 * warn-text = quoted-string 048 * warn-date = <"> HTTP-date <"> 049 * </p> 050 * 051 * <p> 052 * A response MAY carry more than one Warning header. 053 * 054 * <p> 055 * The warn-text SHOULD be in a natural language and character set that is most likely to be intelligible to the human 056 * user receiving the response. 057 * This decision MAY be based on any available knowledge, such as the location of the cache or user, the 058 * Accept-Language field in a request, the Content-Language field in a response, etc. 059 * The default language is English and the default character set is ISO-8859-1. 060 * 061 * <p> 062 * If a character set other than ISO-8859-1 is used, it MUST be encoded in the warn-text using the method described in 063 * RFC 2047. 064 * 065 * <p> 066 * Warning headers can in general be applied to any message, however some specific warn-codes are specific to caches 067 * and can only be applied to response messages. 068 * New Warning headers SHOULD be added after any existing Warning headers. 069 * A cache MUST NOT delete any Warning header that it received with a message. 070 * However, if a cache successfully validates a cache entry, it SHOULD remove any Warning headers previously attached 071 * to that entry except as specified for specific Warning codes. 072 * It MUST then add any Warning headers received in the validating response. 073 * In other words, Warning headers are those that would be attached to the most recent relevant response. 074 * 075 * <p> 076 * When multiple Warning headers are attached to a response, the user agent ought to inform the user of as many of them 077 * as possible, in the order that they appear in the response. 078 * If it is not possible to inform the user of all of the warnings, the user agent SHOULD follow these heuristics: 079 * <ul> 080 * <li>Warnings that appear early in the response take priority over those appearing later in the response. 081 * <li>Warnings in the user's preferred character set take priority over warnings in other character sets but with 082 * identical warn-codes and warn-agents. 083 * </ul> 084 * 085 * <p> 086 * Systems that generate multiple Warning headers SHOULD order them with this user agent behavior in mind. 087 * 088 * <p> 089 * Requirements for the behavior of caches with respect to Warnings are stated in section 13.1.2. 090 * 091 * <p> 092 * This is a list of the currently-defined warn-codes, each with a recommended warn-text in English, and a description 093 * of its meaning. 094 * <ul> 095 * <li>110 Response is stale MUST be included whenever the returned response is stale. 096 * <li>111 Revalidation failed MUST be included if a cache returns a stale response because an attempt to revalidate 097 * the response failed, due to an inability to reach the server. 098 * <li>112 Disconnected operation SHOULD be included if the cache is intentionally disconnected from the rest of the 099 * network for a period of time. 100 * <li>113 Heuristic expiration MUST be included if the cache heuristically chose a freshness lifetime greater than 101 * 24 hours and the response's age is greater than 24 hours. 102 * <li>199 Miscellaneous warning The warning text MAY include arbitrary information to be presented to a human user, 103 * or logged. A system receiving this warning MUST NOT take any automated action, besides presenting the warning 104 * to the user. 105 * <li>214 Transformation applied MUST be added by an intermediate cache or proxy if it applies any transformation 106 * changing the content-coding (as specified in the Content-Encoding header) or media-type (as specified in the 107 * Content-Type header) of the response, or the entity-body of the response, unless this Warning code already 108 * appears in the response. 109 * <li>299 Miscellaneous persistent warning The warning text MAY include arbitrary information to be presented to a 110 * human user, or logged. A system receiving this warning MUST NOT take any automated action. 111 * </ul> 112 * 113 * <p> 114 * If an implementation sends a message with one or more Warning headers whose version is HTTP/1.0 or lower, then the 115 * sender MUST include in each warning-value a warn-date that matches the date in the response. 116 * 117 * <p> 118 * If an implementation receives a message with a warning-value that includes a warn-date, and that warn-date is 119 * different from the Date value in the response, then that warning-value MUST be deleted from the message before 120 * storing, forwarding, or using it. 121 * (This prevents bad consequences of naive caching of Warning header fields.) 122 * If all of the warning-values are deleted for this reason, the Warning header MUST be deleted as well. 123 * 124 * <ul class='seealso'> 125 * <li class='extlink'>{@doc ExtRFC2616} 126 * </ul> 127 */ 128@Header("Warning") 129public class Warning extends BasicStringHeader { 130 131 private static final long serialVersionUID = 1L; 132 133 /** 134 * Convenience creator. 135 * 136 * @param value 137 * The header value. 138 * <br>Can be any of the following: 139 * <ul> 140 * <li>{@link String} 141 * <li>Anything else - Converted to <c>String</c> then parsed. 142 * </ul> 143 * @return A new {@link Warning} object. 144 */ 145 public static Warning of(Object value) { 146 if (value == null) 147 return null; 148 return new Warning(value); 149 } 150 151 /** 152 * Convenience creator using supplier. 153 * 154 * <p> 155 * Header value is re-evaluated on each call to {@link #getValue()}. 156 * 157 * @param value 158 * The header value supplier. 159 * <br>Can be any of the following: 160 * <ul> 161 * <li>{@link String} 162 * <li>Anything else - Converted to <c>String</c> then parsed. 163 * </ul> 164 * @return A new {@link Warning} object. 165 */ 166 public static Warning of(Supplier<?> value) { 167 if (value == null) 168 return null; 169 return new Warning(value); 170 } 171 172 /** 173 * Constructor. 174 * 175 * @param value 176 * The header value. 177 * <br>Can be any of the following: 178 * <ul> 179 * <li>{@link String} 180 * <li>Anything else - Converted to <c>String</c> then parsed. 181 * <li>A {@link Supplier} of anything on this list. 182 * </ul> 183 */ 184 public Warning(Object value) { 185 super("Warning", value); 186 } 187 188 /** 189 * Constructor 190 * 191 * @param value 192 * The header value. 193 */ 194 public Warning(String value) { 195 this((Object)value); 196 } 197}