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>Trailer</l> HTTP response header.
021 *
022 * <p>
023 * The Trailer general field value indicates that the given set of header fields is present in the trailer of a message
024 * encoded with chunked transfer coding.
025 *
026 * <h5 class='figure'>Example</h5>
027 * <p class='bcode'>
028 *    Trailer: Max-Forwards
029 * </p>
030 *
031 * <h5 class='topic'>RFC2616 Specification</h5>
032 *
033 * The Trailer general field value indicates that the given set of header fields is present in the trailer of a message
034 * encoded with chunked transfer-coding.
035 *
036 * <p class='bcode'>
037 *    Trailer  = "Trailer" ":" 1#field-name
038 * </p>
039 *
040 * <p>
041 * An HTTP/1.1 message SHOULD include a Trailer header field in a message using chunked transfer-coding with a non-empty
042 * trailer.
043 * Doing so allows the recipient to know which header fields to expect in the trailer.
044 *
045 * <p>
046 * If no Trailer header field is present, the trailer SHOULD NOT include any header fields.
047 * See section 3.6.1 for restrictions on the use of trailer fields in a "chunked" transfer-coding.
048 *
049 * <p>
050 * Message header fields listed in the Trailer header field MUST NOT include the following header fields:
051 * <ul>
052 *    <li>Transfer-Encoding
053 *    <li>Content-Length
054 *    <li>Trailer
055 * </ul>
056 *
057 * <h5 class='section'>See Also:</h5><ul>
058 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
059 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
060 * </ul>
061 *
062 * @serial exclude
063 */
064@Header("Trailer")
065public class Trailer extends BasicStringHeader {
066
067   //-----------------------------------------------------------------------------------------------------------------
068   // Static
069   //-----------------------------------------------------------------------------------------------------------------
070
071   private static final long serialVersionUID = 1L;
072   private static final String NAME = "Trailer";
073
074   /**
075    * Static creator.
076    *
077    * @param value
078    *    The header value.
079    *    <br>Can be <jk>null</jk>.
080    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
081    */
082   public static Trailer of(String value) {
083      return value == null ? null : new Trailer(value);
084   }
085
086   /**
087    * Static creator with delayed value.
088    *
089    * <p>
090    * Header value is re-evaluated on each call to {@link #getValue()}.
091    *
092    * @param value
093    *    The supplier of the header value.
094    *    <br>Can be <jk>null</jk>.
095    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
096    */
097   public static Trailer of(Supplier<String> value) {
098      return value == null ? null : new Trailer(value);
099   }
100
101   //-----------------------------------------------------------------------------------------------------------------
102   // Instance
103   //-----------------------------------------------------------------------------------------------------------------
104
105   /**
106    * Constructor.
107    *
108    * @param value
109    *    The header value.
110    *    <br>Can be <jk>null</jk>.
111    */
112   public Trailer(String value) {
113      super(NAME, value);
114   }
115
116   /**
117    * Constructor with delayed value.
118    *
119    * <p>
120    * Header value is re-evaluated on each call to {@link #getValue()}.
121    *
122    * @param value
123    *    The supplier of the header value.
124    *    <br>Can be <jk>null</jk>.
125    */
126   public Trailer(Supplier<String> value) {
127      super(NAME, value);
128   }
129}