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   private static final long serialVersionUID = 1L;
071   private static final String NAME = "Max-Forwards";
072
073   /**
074    * Static creator.
075    *
076    * @param value
077    *    The header value.
078    *    <br>Can be <jk>null</jk>.
079    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
080    */
081   public static MaxForwards of(Integer value) {
082      return value == null ? null : new MaxForwards(value);
083   }
084
085   /**
086    * Static creator.
087    *
088    * @param value
089    *    The header value.
090    *    <br>Must be parsable using {@link Integer#parseInt(String)}.
091    *    <br>Can be <jk>null</jk>.
092    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
093    */
094   public static MaxForwards of(String value) {
095      return value == null ? null : new MaxForwards(value);
096   }
097
098   /**
099    * Static creator with delayed value.
100    *
101    * <p>
102    * Header value is re-evaluated on each call to {@link #getValue()}.
103    *
104    * @param value
105    *    The supplier of the header value.
106    *    <br>Can be <jk>null</jk>.
107    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
108    */
109   public static MaxForwards of(Supplier<Integer> value) {
110      return value == null ? null : new MaxForwards(value);
111   }
112
113   /**
114    * Constructor.
115    *
116    * @param value
117    *    The header value.
118    *    <br>Can be <jk>null</jk>.
119    */
120   public MaxForwards(Integer value) {
121      super(NAME, value);
122   }
123
124   /**
125    * Constructor.
126    *
127    * @param value
128    *    The header value.
129    *    <br>Must be parsable using {@link Integer#parseInt(String)}.
130    *    <br>Can be <jk>null</jk>.
131    */
132   public MaxForwards(String value) {
133      super(NAME, value);
134   }
135
136   /**
137    * Constructor with delayed value.
138    *
139    * <p>
140    * Header value is re-evaluated on each call to {@link #getValue()}.
141    *
142    * @param value
143    *    The supplier of the header value.
144    *    <br>Can be <jk>null</jk>.
145    */
146   public MaxForwards(Supplier<Integer> value) {
147      super(NAME, value);
148   }
149}