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>If-Match</l> HTTP request header. 019 * 020 * <p> 021 * Only perform the action if the client supplied entity matches the same entity on the server. 022 * This is mainly for methods like PUT to only update a resource if it has not been modified since the user last 023 * updated it. 024 * 025 * <h5 class='figure'>Example</h5> 026 * <p class='bcode w800'> 027 * If-Match: "737060cd8c284d8af7ad3082f209582d" 028 * </p> 029 * 030 * <h5 class='topic'>RFC2616 Specification</h5> 031 * 032 * The If-Match request-header field is used with a method to make it conditional. 033 * A client that has one or more entities previously obtained from the resource can verify that one of those entities 034 * is current by including a list of their associated entity tags in the If-Match header field. 035 * Entity tags are defined in section 3.11. 036 * The purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction 037 * overhead. 038 * It is also used, on updating requests, to prevent inadvertent modification of the wrong version of a resource. 039 * As a special case, the value "*" matches any current entity of the resource. 040 * 041 * <p class='bcode w800'> 042 * If-Match = "If-Match" ":" ( "*" | 1#entity-tag ) 043 * </p> 044 * 045 * <p> 046 * If any of the entity tags match the entity tag of the entity that would have been returned in the response to a 047 * similar GET request (without the If-Match header) on that resource, or if "*" is given and any current entity exists 048 * for that resource, then the server MAY perform the requested method as if the If-Match header field did not exist. 049 * 050 * <p> 051 * A server MUST use the strong comparison function (see section 13.3.3) to compare the entity tags in If-Match. 052 * 053 * <p> 054 * If none of the entity tags match, or if "*" is given and no current entity exists, the server MUST NOT perform the 055 * requested method, and MUST return a 412 (Precondition Failed) response. 056 * This behavior is most useful when the client wants to prevent an updating method, such as PUT, from modifying a 057 * resource that has changed since the client last retrieved it. 058 * 059 * <p> 060 * If the request would, without the If-Match header field, result in anything other than a 2xx or 412 status, then the 061 * If-Match header MUST be ignored. 062 * 063 * <p> 064 * The meaning of "If-Match: *" is that the method SHOULD be performed if the representation selected by the origin 065 * server (or by a cache, possibly using the Vary mechanism, see section 14.44) exists, and MUST NOT be performed if the 066 * representation does not exist. 067 * 068 * <p> 069 * A request intended to update a resource (e.g., a PUT) MAY include an If-Match header field to signal that the request 070 * method MUST NOT be applied if the entity corresponding to the If-Match value (a single entity tag) is no longer a 071 * representation of that resource. 072 * This allows the user to indicate that they do not wish the request to be successful if the resource has been changed 073 * without their knowledge. 074 * 075 * <p> 076 * Examples: 077 * <p class='bcode w800'> 078 * If-Match: "xyzzy" 079 * If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 080 * If-Match: * 081 * </p> 082 * 083 * <p> 084 * The result of a request having both an If-Match header field and either an If-None-Match or an If-Modified-Since 085 * header fields is undefined by this specification. 086 * 087 * <h5 class='section'>See Also:</h5> 088 * <ul class='doctree'> 089 * <li class='extlink'>{@doc RFC2616} 090 * </ul> 091 */ 092@Header("If-Match") 093public final class IfMatch extends HeaderEntityValidatorArray { 094 095 /** 096 * Returns a parsed <code>If-Match</code> header. 097 * 098 * @param value The <code>If-Match</code> header string. 099 * @return The parsed <code>If-Match</code> header, or <jk>null</jk> if the string was null. 100 */ 101 public static IfMatch forString(String value) { 102 if (value == null) 103 return null; 104 return new IfMatch(value); 105 } 106 107 private IfMatch(String value) { 108 super(value); 109 } 110}