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-Modified-Since</l> HTTP request header.
019 *
020 * <p>
021 * Allows a 304 Not Modified to be returned if content is unchanged.
022 *
023 * <h5 class='figure'>Example</h5>
024 * <p class='bcode w800'>
025 *    If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
026 * </p>
027 *
028 * <h5 class='topic'>RFC2616 Specification</h5>
029 *
030 * The If-Modified-Since request-header field is used with a method to make it conditional:
031 * if the requested variant has not been modified since the time specified in this field, an entity will not be returned
032 * from the server; instead, a 304 (not modified) response will be returned without any message-body.
033 *
034 * <p class='bcode w800'>
035 *    If-Modified-Since = "If-Modified-Since" ":" HTTP-date
036 * </p>
037 *
038 * <p>
039 * An example of the field is:
040 * <p class='bcode w800'>
041 *    If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
042 * </p>
043 *
044 * <p>
045 * A GET method with an If-Modified-Since header and no Range header requests that the identified entity be transferred
046 * only if it has been modified since the date given by the If-Modified-Since header.
047 * The algorithm for determining this includes the following cases:
048 * <ol>
049 *    <li>If the request would normally result in anything other than a 200 (OK) status, or if the passed
050 *       If-Modified-Since date is invalid, the response is exactly the same as for a normal GET.
051 *       A date which is later than the server's current time is invalid.
052 *    <li>If the variant has been modified since the If-Modified-Since date, the response is exactly the same as for a
053 *       normal GET.
054 *    <li>If the variant has not been modified since a valid If-Modified-Since date, the server SHOULD return a 304
055 *       (Not Modified) response.
056 * </ol>
057 *
058 * <p>
059 * The purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction
060 * overhead.
061 *
062 * <p>
063 * Note: The Range request-header field modifies the meaning of If-Modified-Since; see section 14.35 for full details.
064 *
065 * <p>
066 * Note: If-Modified-Since times are interpreted by the server, whose clock might not be synchronized with the client.
067 *
068 * <p>
069 * Note: When handling an If-Modified-Since header field, some servers will use an exact date comparison function,
070 * rather than a less-than function, for deciding whether to send a 304 (Not Modified) response.
071 * To get best results when sending an If-Modified-Since header field for cache validation, clients are
072 * advised to use the exact date string received in a previous Last-Modified header field whenever possible.
073 *
074 * <p>
075 * Note: If a client uses an arbitrary date in the If-Modified-Since header instead of a date taken from the
076 * Last-Modified header for the same request, the client should be aware of the fact that this date is interpreted in
077 * the server's understanding of time.
078 * The client should consider unsynchronized clocks and rounding problems due to the different encodings of time between
079 * the client and server.
080 * This includes the possibility of race conditions if the document has changed between the time it was first requested
081 * and the If-Modified-Since date of a subsequent request, and the possibility of clock-skew-related problems if the
082 * If-Modified-Since date is derived from the client's clock without correction to the server's clock.
083 * Corrections for different time bases between client and server are at best approximate due to network latency.
084 * The result of a request having both an If-Modified-Since header field and either an If-Match or an
085 * If-Unmodified-Since header fields is undefined by this specification.
086 *
087 * <ul class='seealso'>
088 *    <li class='extlink'>{@doc RFC2616}
089 * </ul>
090 */
091@Header("If-Modified-Since")
092public final class IfModifiedSince extends HeaderDate {
093
094   /**
095    * Returns a parsed <c>If-Modified-Since</c> header.
096    *
097    * @param value The <c>If-Modified-Since</c> header string.
098    * @return The parsed <c>If-Modified-Since</c> header, or <jk>null</jk> if the string was null.
099    */
100   public static IfModifiedSince forString(String value) {
101      if (value == null)
102         return null;
103      return new IfModifiedSince(value);
104   }
105
106   private IfModifiedSince(String value) {
107      super(value);
108   }
109}