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>Max-Forwards</l> HTTP request header. 025 * 026 * <p> 027 * Limit the number of times the message can be forwarded through proxies or gateways. 028 * 029 * <h5 class='figure'>Example</h5> 030 * <p class='bcode'> 031 * Max-Forwards: 10 032 * </p> 033 * 034 * <h5 class='topic'>RFC2616 Specification</h5> 035 * 036 * The Max-Forwards request-header field provides a mechanism with the TRACE (section 9.8) and OPTIONS (section 9.2) 037 * methods to limit the number of proxies or gateways that can forward the request to the next inbound server. 038 * This can be useful when the client is attempting to trace a request chain which appears to be failing or looping in 039 * mid-chain. 040 * 041 * <p class='bcode'> 042 * Max-Forwards = "Max-Forwards" ":" 1*DIGIT 043 * </p> 044 * 045 * <p> 046 * The Max-Forwards value is a decimal integer indicating the remaining number of times this request message may be 047 * forwarded. 048 * 049 * <p> 050 * Each proxy or gateway recipient of a TRACE or OPTIONS request containing a Max-Forwards header field MUST check and 051 * update its value prior to forwarding the request. 052 * If the received value is zero (0), the recipient MUST NOT forward the request; instead, it MUST respond as the final 053 * recipient. 054 * If the received Max-Forwards value is greater than zero, then the forwarded message MUST contain an updated 055 * Max-Forwards field with a value decremented by one (1). 056 * 057 * <p> 058 * The Max-Forwards header field MAY be ignored for all other methods defined by this specification and for any 059 * extension methods for which it is not explicitly referred to as part of that method definition. 060 * 061 * <h5 class='section'>See Also:</h5><ul> 062 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 063 * <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a> 064 * </ul> 065 * 066 * @serial exclude 067 */ 068@Header("Max-Forwards") 069public class MaxForwards extends BasicIntegerHeader { 070 071 //----------------------------------------------------------------------------------------------------------------- 072 // Static 073 //----------------------------------------------------------------------------------------------------------------- 074 075 private static final long serialVersionUID = 1L; 076 private static final String NAME = "Max-Forwards"; 077 078 /** 079 * Static creator. 080 * 081 * @param value 082 * The header value. 083 * <br>Must be parsable using {@link Integer#parseInt(String)}. 084 * <br>Can be <jk>null</jk>. 085 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 086 */ 087 public static MaxForwards of(String value) { 088 return value == null ? null : new MaxForwards(value); 089 } 090 091 /** 092 * Static creator. 093 * 094 * @param value 095 * The header value. 096 * <br>Can be <jk>null</jk>. 097 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 098 */ 099 public static MaxForwards of(Integer value) { 100 return value == null ? null : new MaxForwards(value); 101 } 102 103 /** 104 * Static creator with delayed value. 105 * 106 * <p> 107 * Header value is re-evaluated on each call to {@link #getValue()}. 108 * 109 * @param value 110 * The supplier of the header value. 111 * <br>Can be <jk>null</jk>. 112 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 113 */ 114 public static MaxForwards of(Supplier<Integer> value) { 115 return value == null ? null : new MaxForwards(value); 116 } 117 118 //----------------------------------------------------------------------------------------------------------------- 119 // Instance 120 //----------------------------------------------------------------------------------------------------------------- 121 122 /** 123 * Constructor. 124 * 125 * @param value 126 * The header value. 127 * <br>Must be parsable using {@link Integer#parseInt(String)}. 128 * <br>Can be <jk>null</jk>. 129 */ 130 public MaxForwards(String value) { 131 super(NAME, value); 132 } 133 134 /** 135 * Constructor. 136 * 137 * @param value 138 * The header value. 139 * <br>Can be <jk>null</jk>. 140 */ 141 public MaxForwards(Integer value) { 142 super(NAME, value); 143 } 144 145 /** 146 * Constructor with delayed value. 147 * 148 * <p> 149 * Header value is re-evaluated on each call to {@link #getValue()}. 150 * 151 * @param value 152 * The supplier of the header value. 153 * <br>Can be <jk>null</jk>. 154 */ 155 public MaxForwards(Supplier<Integer> value) { 156 super(NAME, value); 157 } 158}