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.time.*; 016import java.util.*; 017import java.util.function.*; 018 019import org.apache.juneau.http.annotation.*; 020 021/** 022 * Represents a parsed <l>If-Unmodified-Since</l> HTTP request header. 023 * 024 * <p> 025 * Only send the response if the entity has not been modified since a specific time. 026 * 027 * <h5 class='figure'>Example</h5> 028 * <p class='bcode w800'> 029 * If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT 030 * </p> 031 * 032 * <h5 class='topic'>RFC2616 Specification</h5> 033 * 034 * The If-Unmodified-Since request-header field is used with a method to make it conditional. 035 * If the requested resource has not been modified since the time specified in this field, the server SHOULD perform the 036 * requested operation as if the If-Unmodified-Since header were not present. 037 * 038 * <p> 039 * If the requested variant has been modified since the specified time, the server MUST NOT perform the requested 040 * operation, and MUST return a 412 (Precondition Failed). 041 * 042 * <p class='bcode w800'> 043 * If-Unmodified-Since = "If-Unmodified-Since" ":" HTTP-date 044 * </p> 045 * 046 * <p> 047 * An example of the field is: 048 * <p class='bcode w800'> 049 * If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT 050 * </p> 051 * 052 * <p> 053 * If the request normally (i.e., without the If-Unmodified-Since header) would result in anything other than a 2xx or 054 * 412 status, the If-Unmodified-Since header SHOULD be ignored. 055 * 056 * <p> 057 * If the specified date is invalid, the header is ignored. 058 * 059 * <p> 060 * The result of a request having both an If-Unmodified-Since header field and either an If-None-Match or an 061 * If-Modified-Since header fields is undefined by this specification. 062 * 063 * <ul class='seealso'> 064 * <li class='extlink'>{@doc ExtRFC2616} 065 * </ul> 066 */ 067@Header("If-Unmodified-Since") 068public class IfUnmodifiedSince extends BasicDateHeader { 069 070 private static final long serialVersionUID = 1L; 071 072 /** 073 * Convenience creator. 074 * 075 * @param value 076 * The header value. 077 * <br>Can be any of the following: 078 * <ul> 079 * <li><c>String</c> - An RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 080 * <li>{@link ZonedDateTime} 081 * <li>{@link Calendar} 082 * <li>Anything else - Converted to <c>String</c>. 083 * </ul> 084 * @return A new {@link IfUnmodifiedSince} object, or <jk>null</jk> if the value was null. 085 */ 086 public static IfUnmodifiedSince of(Object value) { 087 if (value == null) 088 return null; 089 return new IfUnmodifiedSince(value); 090 } 091 092 /** 093 * Convenience creator using supplier. 094 * 095 * <p> 096 * Header value is re-evaluated on each call to {@link #getValue()}. 097 * 098 * @param value 099 * The header value supplier. 100 * <br>Can be any of the following: 101 * <ul> 102 * <li><c>String</c> - An RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 103 * <li>{@link ZonedDateTime} 104 * <li>{@link Calendar} 105 * <li>Anything else - Converted to <c>String</c>. 106 * </ul> 107 * @return A new {@link IfUnmodifiedSince} object, or <jk>null</jk> if the value was null. 108 */ 109 public static IfUnmodifiedSince of(Supplier<?> value) { 110 if (value == null) 111 return null; 112 return new IfUnmodifiedSince(value); 113 } 114 115 /** 116 * Constructor. 117 * 118 * @param value 119 * The header value. 120 * <br>Can be any of the following: 121 * <ul> 122 * <li><c>String</c> - An RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 123 * <li>{@link ZonedDateTime} 124 * <li>{@link Calendar} 125 * <li>Anything else - Converted to <c>String</c>. 126 * <li>A {@link Supplier} of anything on this list. 127 * </ul> 128 */ 129 public IfUnmodifiedSince(Object value) { 130 super("If-Unmodified-Since", value); 131 } 132 133 /** 134 * Constructor 135 * 136 * @param value 137 * The header value. 138 */ 139 public IfUnmodifiedSince(String value) { 140 this((Object)value); 141 } 142}