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.function.*;
016
017import org.apache.juneau.http.annotation.*;
018
019/**
020 * Represents a parsed <l>Content-Encoding</l> HTTP response header.
021 *
022 * <p>
023 * The type of encoding used on the data.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode w800'>
027 *    Content-Encoding: gzip
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The Content-Encoding entity-header field is used as a modifier to the media-type.
033 * When present, its value indicates what additional content codings have been applied to the entity-body, and thus
034 * what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type header
035 * field.
036 * Content-Encoding is primarily used to allow a document to be compressed without losing the identity of its
037 * underlying media type.
038 * <p class='bcode w800'>
039 *    Content-Encoding  = "Content-Encoding" ":" 1#content-coding
040 * </p>
041 *
042 * <p>
043 * Content codings are defined in section 3.5. An example of its use is...
044 * <p class='bcode w800'>
045 *    Content-Encoding: gzip
046 * </p>
047 *
048 * <p>
049 * The content-coding is a characteristic of the entity identified by the Request-URI.
050 * Typically, the entity-body is stored with this encoding and is only decoded before rendering or analogous usage.
051 * However, a non-transparent proxy MAY modify the content-coding if the new coding is known to be acceptable to the
052 * recipient, unless the "no-transform" cache-control directive is present in the message.
053 *
054 * <p>
055 * If the content-coding of an entity is not "identity", then the response MUST include a Content-Encoding
056 * entity-header (section 14.11) that lists the non-identity content-coding(s) used.
057 *
058 * <p>
059 * If the content-coding of an entity in a request message is not acceptable to the origin server, the server SHOULD
060 * respond with a status code of 415 (Unsupported Media Type).
061 *
062 * <p>
063 * If multiple encodings have been applied to an entity, the content codings MUST be listed in the order in which they
064 * were applied.
065 * Additional information about the encoding parameters MAY be provided.
066 *
067 * <ul class='seealso'>
068 *    <li class='extlink'>{@doc ExtRFC2616}
069 * </ul>
070 */
071@Header(name="Content-Encoding",_enum={"gzip","compress","deflate","identity","other"})
072public class ContentEncoding extends BasicStringHeader {
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>{@link String}
084    *       <li>Anything else - Converted to <c>String</c> then parsed.
085    *    </ul>
086    * @return A new {@link ContentEncoding} object.
087    */
088   public static ContentEncoding of(Object value) {
089      if (value == null)
090         return null;
091      return new ContentEncoding(value);
092   }
093
094   /**
095    * Convenience creator using supplier.
096    *
097    * <p>
098    * Header value is re-evaluated on each call to {@link #getValue()}.
099    *
100    * @param value
101    *    The header value supplier.
102    *    <br>Can be any of the following:
103    *    <ul>
104    *       <li>{@link String}
105    *       <li>Anything else - Converted to <c>String</c> then parsed.
106    *    </ul>
107    * @return A new {@link ContentEncoding} object.
108    */
109   public static ContentEncoding of(Supplier<?> value) {
110      if (value == null)
111         return null;
112      return new ContentEncoding(value);
113   }
114
115   /**
116    * Constructor.
117    *
118    * @param value
119    *    The header value.
120    *    <br>Can be any of the following:
121    *    <ul>
122    *       <li>{@link String}
123    *       <li>Anything else - Converted to <c>String</c> then parsed.
124    *       <li>A {@link Supplier} of anything on this list.
125    *    </ul>
126    */
127   public ContentEncoding(Object value) {
128      super("Content-Encoding", value);
129   }
130
131   /**
132    * Constructor
133    *
134    * @param value
135    *    The header value.
136    */
137   public ContentEncoding(String value) {
138      this((Object)value);
139   }
140}