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.header; 014 015import java.util.*; 016import java.util.function.*; 017 018import org.apache.juneau.http.annotation.*; 019 020/** 021 * Represents a parsed <l>Allow</l> HTTP response header. 022 * 023 * <p> 024 * Valid methods for a specified resource. To be used for a 405 Method not allowed. 025 * 026 * <h5 class='figure'>Example</h5> 027 * <p class='bcode w800'> 028 * Allow: GET, HEAD 029 * </p> 030 * 031 * <h5 class='topic'>RFC2616 Specification</h5> 032 * 033 * The Allow entity-header field lists the set of methods supported by the resource identified by the Request-URI. 034 * The purpose of this field is strictly to inform the recipient of valid methods associated with the resource. 035 * An Allow header field MUST be present in a 405 (Method Not Allowed) response. 036 * 037 * <p class='bcode w800'> 038 * Allow = "Allow" ":" #Method 039 * </p> 040 * 041 * <p> 042 * Example of use: 043 * <p class='bcode w800'> 044 * Allow: GET, HEAD, PUT 045 * </p> 046 * 047 * <p> 048 * This field cannot prevent a client from trying other methods. 049 * However, the indications given by the Allow header field value SHOULD be followed. 050 * 051 * <p> 052 * The actual set of allowed methods is defined by the origin server at the time of each request. 053 * 054 * <p> 055 * The Allow header field MAY be provided with a PUT request to recommend the methods to be supported by the new or 056 * modified resource. 057 * 058 * <p> 059 * The server is not required to support these methods and SHOULD include an Allow header in the response giving the 060 * actual supported methods. 061 * 062 * <p> 063 * A proxy MUST NOT modify the Allow header field even if it does not understand all the methods specified, since the 064 * user agent might 065 * have other means of communicating with the origin server. 066 * 067 * <ul class='seealso'> 068 * <li class='extlink'>{@doc ExtRFC2616} 069 * </ul> 070 */ 071@Header("Allow") 072public class Allow extends BasicCsvArrayHeader { 073 074 private static final long serialVersionUID = 1L; 075 076 /** 077 * Convenience creator. 078 * 079 * @param value 080 * The header value. 081 * <br>Can be any of the following: 082 * <ul> 083 * <li><c>String</c> - A comma-delimited string. 084 * <li><c>String[]</c> - A pre-parsed value. 085 * <li>Any other array type - Converted to <c>String[]</c>. 086 * <li>Any {@link Collection} - Converted to <c>String[]</c>. 087 * <li>Anything else - Converted to <c>String</c>. 088 * </ul> 089 * @return The parsed <c>Allow</c> header, or <jk>null</jk> if the value was null. 090 */ 091 public static Allow of(Object value) { 092 if (value == null) 093 return null; 094 return new Allow(value); 095 } 096 097 /** 098 * Convenience creator using supplier. 099 * 100 * <p> 101 * Header value is re-evaluated on each call to {@link #getValue()}. 102 * 103 * @param value 104 * The header value supplier. 105 * <br>Can be any of the following: 106 * <ul> 107 * <li><c>String</c> - A comma-delimited string. 108 * <li><c>String[]</c> - A pre-parsed value. 109 * <li>Any other array type - Converted to <c>String[]</c>. 110 * <li>Any {@link Collection} - Converted to <c>String[]</c>. 111 * <li>Anything else - Converted to <c>String</c>. 112 * </ul> 113 * @return The parsed <c>Allow</c> header, or <jk>null</jk> if the value was null. 114 */ 115 public static Allow of(Supplier<?> value) { 116 if (value == null) 117 return null; 118 return new Allow(value); 119 } 120 121 /** 122 * Constructor. 123 * 124 * @param value 125 * The header value. 126 * <br>Can be any of the following: 127 * <ul> 128 * <li><c>String</c> - A comma-delimited string. 129 * <li><c>String[]</c> - A pre-parsed value. 130 * <li>Any other array type - Converted to <c>String[]</c>. 131 * <li>Any {@link Collection} - Converted to <c>String[]</c>. 132 * <li>Anything else - Converted to <c>String</c>. 133 * <li>A {@link Supplier} of anything on this list. 134 * </ul> 135 */ 136 public Allow(Object value) { 137 super("Allow", value); 138 } 139 140 /** 141 * Constructor 142 * 143 * @param value 144 * The header value. 145 */ 146 public Allow(String value) { 147 this((Object)value); 148 } 149}