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.classic.header; 018 019import java.util.function.*; 020 021import org.apache.juneau.http.*; 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/JuneauRestCommon">juneau-rest-common</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") 078@SuppressWarnings({ 079 "java:S9149" // Public Juneau DSL factory; hiding parent of()/create() is intentional. 080}) 081public class Allow extends BasicCsvHeader { 082 private static final long serialVersionUID = 1L; 083 private static final String NAME = "Allow"; 084 085 /** 086 * Static creator. 087 * 088 * @param value 089 * The header value. 090 * <br>Can be <jk>null</jk>. 091 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 092 */ 093 public static Allow of(String value) { 094 return value == null ? null : new Allow(value); 095 } 096 097 /** 098 * Static creator. 099 * 100 * @param value 101 * The header value. 102 * <br>Can be <jk>null</jk>. 103 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 104 */ 105 public static Allow of(String...value) { 106 return value == null ? null : new Allow(value); 107 } 108 109 /** 110 * Static creator for two CSV tokens. 111 * 112 * <p> 113 * This distinct fixed-arity overload ensures two literal {@link String} arguments resolve to this class's own 114 * factory (returning an {@link Allow}) rather than the inherited fixed-arity {@link BasicCsvHeader#of(String,String)}, 115 * which Java overload resolution would otherwise prefer. 116 * 117 * @param value1 The first CSV token. 118 * @param value2 The second CSV token. 119 * @return A new header bean. 120 */ 121 public static Allow of(String value1, String value2) { 122 return new Allow(value1, value2); 123 } 124 125 /** 126 * Static creator with delayed value. 127 * 128 * <p> 129 * Header value is re-evaluated on each call to {@link #getValue()}. 130 * 131 * @param value 132 * The supplier of the header value. 133 * <br>Can be <jk>null</jk>. 134 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 135 */ 136 public static Allow of(Supplier<String[]> value) { 137 return value == null ? null : new Allow(value); 138 } 139 140 /** 141 * Constructor. 142 * 143 * @param value 144 * The header value. 145 * <br>Can be <jk>null</jk> to create a header with no value. 146 */ 147 public Allow(String value) { 148 super(NAME, value); 149 } 150 151 /** 152 * Constructor. 153 * 154 * @param value 155 * The header value. 156 * <br>Can be <jk>null</jk> or empty to create a header with no value. 157 */ 158 public Allow(String...value) { 159 super(NAME, value); 160 } 161 162 /** 163 * Constructor with delayed value. 164 * 165 * <p> 166 * Header value is re-evaluated on each call to {@link #getValue()}. 167 * 168 * @param value 169 * The supplier of the header value. 170 * <br>Can be <jk>null</jk> to create a header with no value. 171 */ 172 public Allow(Supplier<String[]> value) { 173 super(NAME, value); 174 } 175}