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