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