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