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