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>Max-Forwards</l> HTTP request header.
019 *
020 * <p>
021 * Limit the number of times the message can be forwarded through proxies or gateways.
022 *
023 * <h5 class='figure'>Example</h5>
024 * <p class='bcode w800'>
025 *    Max-Forwards: 10
026 * </p>
027 *
028 * <h5 class='topic'>RFC2616 Specification</h5>
029 *
030 * The Max-Forwards request-header field provides a mechanism with the TRACE (section 9.8) and OPTIONS (section 9.2)
031 * methods to limit the number of proxies or gateways that can forward the request to the next inbound server.
032 * This can be useful when the client is attempting to trace a request chain which appears to be failing or looping in
033 * mid-chain.
034 *
035 * <p class='bcode w800'>
036 *    Max-Forwards   = "Max-Forwards" ":" 1*DIGIT
037 * </p>
038 *
039 * <p>
040 * The Max-Forwards value is a decimal integer indicating the remaining number of times this request message may be
041 * forwarded.
042 *
043 * <p>
044 * Each proxy or gateway recipient of a TRACE or OPTIONS request containing a Max-Forwards header field MUST check and
045 * update its value prior to forwarding the request.
046 * If the received value is zero (0), the recipient MUST NOT forward the request; instead, it MUST respond as the final
047 * recipient.
048 * If the received Max-Forwards value is greater than zero, then the forwarded message MUST contain an updated
049 * Max-Forwards field with a value decremented by one (1).
050 *
051 * <p>
052 * The Max-Forwards header field MAY be ignored for all other methods defined by this specification and for any
053 * extension methods for which it is not explicitly referred to as part of that method definition.
054 *
055 * <ul class='seealso'>
056 *    <li class='extlink'>{@doc RFC2616}
057 * </ul>
058 */
059@Header("Max-Forwards")
060public final class MaxForwards extends HeaderInteger {
061
062   /**
063    * Constructor.
064    *
065    * @param value The value for this header.
066    */
067   public MaxForwards(Integer value) {
068      super(value);
069   }
070
071   /**
072    * Returns a parsed <c>Max-Forwards</c> header.
073    *
074    * @param value The <c>Max-Forwards</c> header string.
075    * @return The parsed <c>Max-Forwards</c> header, or <jk>null</jk> if the string was null.
076    */
077   public static MaxForwards forString(String value) {
078      if (value == null)
079         return null;
080      return new MaxForwards(value);
081   }
082
083   private MaxForwards(String value) {
084      super(value);
085   }
086}