001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.http.header;
018
019import java.time.*;
020import java.util.function.*;
021
022import org.apache.juneau.http.annotation.*;
023
024/**
025 * Represents a parsed <l>Expires</l> HTTP response header.
026 *
027 * <p>
028 * Gives the date/time after which the response is considered stale (in "HTTP-date" format as defined by RFC 7231).
029 *
030 * <h5 class='figure'>Example</h5>
031 * <p class='bcode'>
032 *    Expires: Thu, 01 Dec 1994 16:00:00 GMT
033 * </p>
034 *
035 * <h5 class='topic'>RFC2616 Specification</h5>
036 *
037 * The Expires entity-header field gives the date/time after which the response is considered stale.
038 * A stale cache entry may not normally be returned by a cache (either a proxy cache or a user agent cache) unless it is
039 * first validated with the origin server
040 * (or with an intermediate cache that has a fresh copy of the entity).
041 * See section 13.2 for further discussion of the expiration model.
042 *
043 * <p>
044 * The presence of an Expires field does not imply that the original resource will change or cease to exist at, before,
045 * or after that time.
046 *
047 * <p>
048 * The format is an absolute date and time as defined by HTTP-date in section 3.3.1; it MUST be in RFC 1123 date format:
049 *
050 * <p class='bcode'>
051 *    Expires = "Expires" ":" HTTP-date
052 * </p>
053 *
054 * <p>
055 * An example of its use is...
056 * <p class='bcode'>
057 *    Expires: Thu, 01 Dec 1994 16:00:00 GMT
058 * </p>
059 *
060 * <p>
061 * Note: if a response includes a Cache-Control field with the max-age directive (see section 14.9.3), that directive
062 * overrides the Expires field.
063 *
064 * <p>
065 * HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past
066 * (i.e., "already expired").
067 *
068 * <p>
069 * To mark a response as "already expired," an origin server sends an Expires date that is equal to the Date header
070 * value.
071 * (See the rules for expiration calculations in section 13.2.4.)
072 *
073 * <p>
074 * To mark a response as "never expires," an origin server sends an Expires date approximately one year from the time
075 * the response is sent.
076 * HTTP/1.1 servers SHOULD NOT send Expires dates more than one year in the future.
077 *
078 * <p>
079 * The presence of an Expires header field with a date value of some time in the future on a response that otherwise
080 * would by default be non-cacheable indicates that the response is cacheable, unless indicated otherwise by a
081 * Cache-Control header field (section 14.9).
082 *
083 * <h5 class='section'>See Also:</h5><ul>
084 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
085 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
086 * </ul>
087 *
088 * @serial exclude
089 */
090@Header("Expires")
091public class Expires extends BasicDateHeader {
092   private static final long serialVersionUID = 1L;
093   private static final String NAME = "Expires";
094
095   /**
096    * Static creator.
097    *
098    * @param value
099    *    The header value.
100    *    <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>).
101    *    <br>Can be <jk>null</jk>.
102    * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>.
103    */
104   public static Expires of(String value) {
105      return value == null ? null : new Expires(value);
106   }
107
108   /**
109    * Static creator with delayed value.
110    *
111    * <p>
112    * Header value is re-evaluated on each call to {@link #getValue()}.
113    *
114    * @param value
115    *    The supplier of the header value.
116    *    <br>Can be <jk>null</jk>.
117    * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>.
118    */
119   public static Expires of(Supplier<ZonedDateTime> value) {
120      return value == null ? null : new Expires(value);
121   }
122
123   /**
124    * Static creator.
125    *
126    * @param value
127    *    The header value.
128    *    <br>Can be <jk>null</jk>.
129    * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>.
130    */
131   public static Expires of(ZonedDateTime value) {
132      return value == null ? null : new Expires(value);
133   }
134
135   /**
136    * Constructor.
137    *
138    * @param value
139    *    The header value.
140    *    <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>).
141    *    <br>Can be <jk>null</jk>.
142    */
143   public Expires(String value) {
144      super(NAME, value);
145   }
146
147   /**
148    * Constructor with delayed value.
149    *
150    * <p>
151    * Header value is re-evaluated on each call to {@link #getValue()}.
152    *
153    * @param value
154    *    The supplier of the header value.
155    *    <br>Can be <jk>null</jk>.
156    */
157   public Expires(Supplier<ZonedDateTime> value) {
158      super(NAME, value);
159   }
160
161   /**
162    * Constructor.
163    *
164    * @param value
165    *    The header value.
166    *    <br>Can be <jk>null</jk>.
167    */
168   public Expires(ZonedDateTime value) {
169      super(NAME, value);
170   }
171}