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>Transfer-Encoding</l> HTTP response header.
021 *
022 * <p>
023 * The form of encoding used to safely transfer the entity to the user.
024 * Currently defined methods are: chunked, compress, deflate, gzip, identity.
025 *
026 * <h5 class='figure'>Example</h5>
027 * <p class='bcode w800'>
028 *    Transfer-Encoding: chunked
029 * </p>
030 *
031 * <h5 class='topic'>RFC2616 Specification</h5>
032 *
033 * The Transfer-Encoding general-header field indicates what (if any) type of transformation has been applied to the
034 * message body in order to safely transfer it between the sender and the recipient.
035 * This differs from the content-coding in that the transfer-coding is a property of the message, not of the entity.
036 *
037 * <p class='bcode w800'>
038 *    Transfer-Encoding       = "Transfer-Encoding" ":" 1#transfer-coding
039 * </p>
040 *
041 * <p>
042 * Transfer-codings are defined in section 3.6. An example is:
043 *
044 * <p class='bcode w800'>
045 *    Transfer-Encoding: chunked
046 * </p>
047 *
048 * <p>
049 * If multiple encodings have been applied to an entity, the transfer-codings MUST be listed in the order in which
050 * they were applied.
051 * Additional information about the encoding parameters MAY be provided by other entity-header fields not defined by
052 * this specification.
053 *
054 * <p>
055 * Many older HTTP/1.0 applications do not understand the Transfer-Encoding header.
056 *
057 * <ul class='seealso'>
058 *    <li class='extlink'>{@doc ExtRFC2616}
059 * </ul>
060 */
061@Header("Transfer-Encoding")
062public class TransferEncoding extends BasicStringHeader {
063
064   private static final long serialVersionUID = 1L;
065
066   /**
067    * Convenience creator.
068    *
069    * @param value
070    *    The header value.
071    *    <br>Can be any of the following:
072    *    <ul>
073    *       <li>{@link String}
074    *       <li>Anything else - Converted to <c>String</c> then parsed.
075    *    </ul>
076    * @return A new {@link TransferEncoding} object.
077    */
078   public static TransferEncoding of(Object value) {
079      if (value == null)
080         return null;
081      return new TransferEncoding(value);
082   }
083
084   /**
085    * Convenience creator using supplier.
086    *
087    * <p>
088    * Header value is re-evaluated on each call to {@link #getValue()}.
089    *
090    * @param value
091    *    The header value supplier.
092    *    <br>Can be any of the following:
093    *    <ul>
094    *       <li>{@link String}
095    *       <li>Anything else - Converted to <c>String</c> then parsed.
096    *    </ul>
097    * @return A new {@link TransferEncoding} object.
098    */
099   public static TransferEncoding of(Supplier<?> value) {
100      if (value == null)
101         return null;
102      return new TransferEncoding(value);
103   }
104
105   /**
106    * Constructor.
107    *
108    * @param value
109    *    The header value.
110    *    <br>Can be any of the following:
111    *    <ul>
112    *       <li>{@link String}
113    *       <li>Anything else - Converted to <c>String</c> then parsed.
114    *       <li>A {@link Supplier} of anything on this list.
115    *    </ul>
116    */
117   public TransferEncoding(Object value) {
118      super("Transfer-Encoding", value);
119   }
120
121   /**
122    * Constructor
123    *
124    * @param value
125    *    The header value.
126    */
127   public TransferEncoding(String value) {
128      this((Object)value);
129   }
130}