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.util.function.*; 020 021import org.apache.juneau.http.annotation.*; 022 023/** 024 * Represents a parsed <l>Age</l> HTTP response header. 025 * 026 * <p> 027 * The age the object has been in a proxy cache in seconds. 028 * 029 * <h5 class='figure'>Example</h5> 030 * <p class='bcode'> 031 * Age: 12 032 * </p> 033 * 034 * <h5 class='topic'>RFC2616 Specification</h5> 035 * 036 * The Age response-header field conveys the sender's estimate of the amount of time since the response (or its 037 * revalidation) was generated at the origin server. 038 * A cached response is "fresh" if its age does not exceed its freshness lifetime. 039 * Age values are calculated as specified in section 13.2.3. 040 * 041 * <p class='bcode'> 042 * Age = "Age" ":" age-value 043 * age-value = delta-seconds 044 * </p> 045 * 046 * <p> 047 * Age values are non-negative decimal integers, representing time in seconds. 048 * 049 * <p> 050 * If a cache receives a value larger than the largest positive integer it can represent, or if any of its age 051 * calculations overflows, it MUST transmit an Age header with a value of 2147483648 (2^31). 052 * 053 * <p> 054 * An HTTP/1.1 server that includes a cache MUST include an Age header field in every response generated from its own 055 * cache. 056 * 057 * <p> 058 * Caches SHOULD use an arithmetic type of at least 31 bits of range. 059 * 060 * <h5 class='section'>See Also:</h5><ul> 061 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 062 * <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a> 063 * </ul> 064 * 065 * @serial exclude 066 */ 067@Header("Age") 068public class Age extends BasicIntegerHeader { 069 070 //----------------------------------------------------------------------------------------------------------------- 071 // Static 072 //----------------------------------------------------------------------------------------------------------------- 073 074 private static final long serialVersionUID = 1L; 075 private static final String NAME = "Age"; 076 077 /** 078 * Static creator. 079 * 080 * @param value 081 * The header value. 082 * <br>Must be parsable using {@link Integer#parseInt(String)}. 083 * <br>Can be <jk>null</jk>. 084 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 085 */ 086 public static Age of(String value) { 087 return value == null ? null : new Age(value); 088 } 089 090 /** 091 * Static creator. 092 * 093 * @param value 094 * The header value. 095 * <br>Can be <jk>null</jk>. 096 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 097 */ 098 public static Age of(Integer value) { 099 return value == null ? null : new Age(value); 100 } 101 102 /** 103 * Static creator with delayed value. 104 * 105 * <p> 106 * Header value is re-evaluated on each call to {@link #getValue()}. 107 * 108 * @param value 109 * The supplier of the header value. 110 * <br>Can be <jk>null</jk>. 111 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 112 */ 113 public static Age of(Supplier<Integer> value) { 114 return value == null ? null : new Age(value); 115 } 116 117 //----------------------------------------------------------------------------------------------------------------- 118 // Instance 119 //----------------------------------------------------------------------------------------------------------------- 120 121 /** 122 * Constructor. 123 * 124 * @param value 125 * The header value. 126 * <br>Must be parsable using {@link Integer#parseInt(String)}. 127 * <br>Can be <jk>null</jk>. 128 */ 129 public Age(String value) { 130 super(NAME, value); 131 } 132 133 /** 134 * Constructor. 135 * 136 * @param value 137 * The header value. 138 * <br>Can be <jk>null</jk>. 139 */ 140 public Age(Integer value) { 141 super(NAME, value); 142 } 143 144 /** 145 * Constructor with delayed value. 146 * 147 * <p> 148 * Header value is re-evaluated on each call to {@link #getValue()}. 149 * 150 * @param value 151 * The supplier of the header value. 152 * <br>Can be <jk>null</jk>. 153 */ 154 public Age(Supplier<Integer> value) { 155 super(NAME, value); 156 } 157}