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