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>Allow</l> HTTP response header.
025 *
026 * <p>
027 * Valid methods for a specified resource. To be used for a 405 Method not allowed.
028 *
029 * <h5 class='figure'>Example</h5>
030 * <p class='bcode'>
031 *    Allow: GET, HEAD
032 * </p>
033 *
034 * <h5 class='topic'>RFC2616 Specification</h5>
035 *
036 * The Allow entity-header field lists the set of methods supported by the resource identified by the Request-URI.
037 * The purpose of this field is strictly to inform the recipient of valid methods associated with the resource.
038 * An Allow header field MUST be present in a 405 (Method Not Allowed) response.
039 *
040 * <p class='bcode'>
041 *    Allow   = "Allow" ":" #Method
042 * </p>
043 *
044 * <p>
045 * Example of use:
046 * <p class='bcode'>
047 *    Allow: GET, HEAD, PUT
048 * </p>
049 *
050 * <p>
051 * This field cannot prevent a client from trying other methods.
052 * However, the indications given by the Allow header field value SHOULD be followed.
053 *
054 * <p>
055 * The actual set of allowed methods is defined by the origin server at the time of each request.
056 *
057 * <p>
058 * The Allow header field MAY be provided with a PUT request to recommend the methods to be supported by the new or
059 * modified resource.
060 *
061 * <p>
062 * The server is not required to support these methods and SHOULD include an Allow header in the response giving the
063 * actual supported methods.
064 *
065 * <p>
066 * A proxy MUST NOT modify the Allow header field even if it does not understand all the methods specified, since the
067 * user agent might
068 * have other means of communicating with the origin server.
069 *
070 * <h5 class='section'>See Also:</h5><ul>
071 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
072 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
073 * </ul>
074 *
075 * @serial exclude
076 */
077@Header("Allow")
078public class Allow extends BasicCsvHeader {
079
080   //-----------------------------------------------------------------------------------------------------------------
081   // Static
082   //-----------------------------------------------------------------------------------------------------------------
083
084   private static final long serialVersionUID = 1L;
085   private static final String NAME = "Allow";
086
087   /**
088    * Static creator.
089    *
090    * @param value
091    *    The header value.
092    *    <br>Can be <jk>null</jk>.
093    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
094    */
095   public static Allow of(String value) {
096      return value == null ? null : new Allow(value);
097   }
098
099   /**
100    * Static creator.
101    *
102    * @param value
103    *    The header value.
104    *    <br>Can be <jk>null</jk>.
105    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
106    */
107   public static Allow of(String...value) {
108      return value == null ? null : new Allow(value);
109   }
110
111   /**
112    * Static creator with delayed value.
113    *
114    * <p>
115    * Header value is re-evaluated on each call to {@link #getValue()}.
116    *
117    * @param value
118    *    The supplier of the header value.
119    *    <br>Can be <jk>null</jk>.
120    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
121    */
122   public static Allow of(Supplier<String[]> value) {
123      return value == null ? null : new Allow(value);
124   }
125
126   //-----------------------------------------------------------------------------------------------------------------
127   // Instance
128   //-----------------------------------------------------------------------------------------------------------------
129
130   /**
131    * Constructor.
132    *
133    * @param value
134    *    The header value.
135    *    <br>Can be <jk>null</jk>.
136    */
137   public Allow(String value) {
138      super(NAME, value);
139   }
140
141   /**
142    * Constructor.
143    *
144    * @param value
145    *    The header value.
146    *    <br>Can be <jk>null</jk>.
147    */
148   public Allow(String...value) {
149      super(NAME, value);
150   }
151
152   /**
153    * Constructor with delayed value.
154    *
155    * <p>
156    * Header value is re-evaluated on each call to {@link #getValue()}.
157    *
158    * @param value
159    *    The supplier of the header value.
160    *    <br>Can be <jk>null</jk>.
161    */
162   public Allow(Supplier<String[]> value) {
163      super(NAME, value);
164   }
165}