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.*; 022import org.apache.juneau.http.annotation.*; 023import org.apache.juneau.internal.*; 024 025 026/** 027 * Represents a parsed <l>Accept-Charset</l> HTTP request header. 028 * 029 * <p> 030 * Character sets that are acceptable. 031 * 032 * <h5 class='figure'>Example</h5> 033 * <p class='bcode'> 034 * Accept-Charset: utf-8 035 * </p> 036 * 037 * <h5 class='topic'>RFC2616 Specification</h5> 038 * 039 * The Accept-Charset request-header field can be used to indicate what character sets are acceptable for the response. 040 * 041 * <p> 042 * This field allows clients capable of understanding more comprehensive or special- purpose character sets to signal 043 * that capability to a server which is capable of representing documents in those character sets. 044 * <p class='bcode'> 045 * Accept-Charset = "Accept-Charset" ":" 046 * 1#( ( charset | "*" )[ ";" "q" "=" qvalue ] ) 047 * </p> 048 * 049 * <p> 050 * Character set values are described in section 3.4. Each charset MAY be given an associated quality value which 051 * represents the user's preference for that charset. 052 * The default value is q=1. 053 * An example is... 054 * <p class='bcode'> 055 * Accept-Charset: iso-8859-5, unicode-1-1;q=0.8 056 * </p> 057 * 058 * <p> 059 * The special value "*", if present in the Accept-Charset field, matches every character set (including ISO-8859-1) 060 * which is not mentioned elsewhere in the Accept-Charset field. 061 * 062 * <p> 063 * If no "*" is present in an Accept-Charset field, then all character sets not explicitly mentioned get a quality 064 * value of 0, except for ISO-8859-1, which gets a quality value of 1 if not explicitly mentioned. 065 * 066 * <p> 067 * If no Accept-Charset header is present, the default is that any character set is acceptable. 068 * 069 * <p> 070 * If an Accept-Charset header is present, and if the server cannot send a response which is acceptable according to 071 * the Accept-Charset header, then the server SHOULD send an error response with the 406 (not acceptable) status code, 072 * though the sending of an unacceptable response is also allowed. 073 * 074 * <h5 class='section'>See Also:</h5><ul> 075 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 076 * <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a> 077 * </ul> 078 * 079 * @serial exclude 080 */ 081@Header("Accept-Charset") 082public class AcceptCharset extends BasicStringRangesHeader { 083 084 //----------------------------------------------------------------------------------------------------------------- 085 // Static 086 //----------------------------------------------------------------------------------------------------------------- 087 088 private static final long serialVersionUID = 1L; 089 private static final String NAME = "Accept-Charset"; 090 091 private static final Cache<String,AcceptCharset> CACHE = Cache.of(String.class, AcceptCharset.class).build(); 092 093 /** 094 * Static creator. 095 * 096 * @param value 097 * The header value. 098 * <br>Must be parsable by {@link StringRanges#of(String)}. 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 AcceptCharset of(String value) { 103 return value == null ? null : CACHE.get(value, ()->new AcceptCharset(value)); 104 } 105 106 /** 107 * Static creator. 108 * 109 * @param value 110 * The header value. 111 * <br>Can be <jk>null</jk>. 112 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 113 */ 114 public static AcceptCharset of(StringRanges value) { 115 return value == null ? null : new AcceptCharset(value); 116 } 117 118 /** 119 * Static creator with delayed value. 120 * 121 * <p> 122 * Header value is re-evaluated on each call to {@link #getValue()}. 123 * 124 * @param value 125 * The supplier of the header value. 126 * <br>Can be <jk>null</jk>. 127 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 128 */ 129 public static AcceptCharset of(Supplier<StringRanges> value) { 130 return value == null ? null : new AcceptCharset(value); 131 } 132 133 //----------------------------------------------------------------------------------------------------------------- 134 // Instance 135 //----------------------------------------------------------------------------------------------------------------- 136 137 /** 138 * Constructor. 139 * 140 * @param value 141 * The header value. 142 * <br>Must be parsable by {@link StringRanges#of(String)}. 143 * <br>Can be <jk>null</jk>. 144 */ 145 public AcceptCharset(String value) { 146 super(NAME, value); 147 } 148 149 /** 150 * Constructor. 151 * 152 * @param value 153 * The header value. 154 * <br>Can be <jk>null</jk>. 155 */ 156 public AcceptCharset(StringRanges value) { 157 super(NAME, value); 158 } 159 160 /** 161 * Constructor with delayed value. 162 * 163 * <p> 164 * Header value is re-evaluated on each call to {@link #getValue()}. 165 * 166 * @param value 167 * The supplier of the header value. 168 * <br>Can be <jk>null</jk>. 169 */ 170 public AcceptCharset(Supplier<StringRanges> value) { 171 super(NAME, value); 172 } 173}