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 w800'> 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 w800'> 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 * <ul class='seealso'> 058 * <li class='extlink'>{@doc ExtRFC2616} 059 * </ul> 060 */ 061@Header("Trailer") 062public class Trailer 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 Trailer} object. 077 */ 078 public static Trailer of(Object value) { 079 if (value == null) 080 return null; 081 return new Trailer(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 Trailer} object. 098 */ 099 public static Trailer of(Supplier<?> value) { 100 if (value == null) 101 return null; 102 return new Trailer(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 Trailer(Object value) { 118 super("Trailer", value); 119 } 120 121 /** 122 * Constructor 123 * 124 * @param value 125 * The header value. 126 */ 127 public Trailer(String value) { 128 this((Object)value); 129 } 130}