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>Via</l> HTTP response header.
025 *
026 * <p>
027 * Informs the client of proxies through which the response was sent.
028 *
029 * <h5 class='figure'>Example</h5>
030 * <p class='bcode'>
031 *    Via: 1.0 fred, 1.1 example.com (Apache/1.1)
032 * </p>
033 *
034 * <p>
035 * Informs the client of proxies through which the response was sent.
036 *
037 * <p>
038 * <h5 class='figure'>Example</h5>
039 * <p class='bcode'>
040 *    Via: 1.0 fred, 1.1 example.com (Apache/1.1)
041 * </p>
042 *
043 * <p>
044 * <h5 class='topic'>RFC2616 Specification</h5>
045 *
046 * The Via general-header field MUST be used by gateways and proxies to indicate the intermediate protocols and
047 * recipients between the user agent and the server on requests, and between the origin server and the client on
048 * responses.
049 * It is analogous to the "Received" field of RFC 822 and is intended to be used for tracking message forwards,
050 * avoiding request loops, and identifying the protocol capabilities of all senders along the request/response chain.
051 *
052 * <p class='bcode'>
053 *    Via =  "Via" ":" 1#( received-protocol received-by [ comment ] )
054 *    received-protocol = [ protocol-name "/" ] protocol-version
055 *    protocol-name     = token
056 *    protocol-version  = token
057 *    received-by       = ( host [ ":" port ] ) | pseudonym
058 *    pseudonym         = token
059 * </p>
060 *
061 * <p>
062 * The received-protocol indicates the protocol version of the message received by the server or client along each
063 * segment of the request/response chain.
064 * The received-protocol version is appended to the Via field value when the message is forwarded so that information
065 * about the protocol capabilities of upstream applications remains visible to all recipients.
066 *
067 * <p>
068 * The protocol-name is optional if and only if it would be "HTTP".
069 * The received-by field is normally the host and optional port number of a recipient server or client that subsequently
070 * forwarded the message.
071 * However, if the real host is considered to be sensitive information, it MAY be replaced by a pseudonym.
072 * If the port is not given, it MAY be assumed to be the default port of the received-protocol.
073 *
074 * <p>
075 * Multiple Via field values represents each proxy or gateway that has forwarded the message.
076 * Each recipient MUST append its information such that the end result is ordered according to the sequence of
077 * forwarding applications.
078 *
079 * <p>
080 * Comments MAY be used in the Via header field to identify the software of the recipient proxy or gateway, analogous
081 * to the User-Agent and Server header fields.
082 * However, all comments in the Via field are optional and MAY be removed by any recipient prior to forwarding the
083 * message.
084 *
085 * <p>
086 * For example, a request message could be sent from an HTTP/1.0 user agent to an internal proxy code-named "fred",
087 * which uses HTTP/1.1 to forward the request to a public proxy at nowhere.com, which completes the request by
088 * forwarding it to the origin server at www.ics.uci.edu.
089 * The request received by www.ics.uci.edu would then have the following Via header field:
090 * <p class='bcode'>
091 *    Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
092 * </p>
093 *
094 * <p>
095 * Proxies and gateways used as a portal through a network firewall SHOULD NOT, by default, forward the names and ports
096 * of hosts within the firewall region.
097 * This information SHOULD only be propagated if explicitly enabled.
098 * If not enabled, the received-by host of any host behind the firewall SHOULD be replaced by an appropriate pseudonym
099 * for that host.
100 *
101 * <p>
102 * For organizations that have strong privacy requirements for hiding internal structures, a proxy MAY combine an
103 * ordered subsequence of Via header field entries with identical received-protocol values into a single such entry.
104 * For example...
105 * <p class='bcode'>
106 *    Via: 1.0 ricky, 1.1 ethel, 1.1 fred, 1.0 lucy
107 * </p>
108 *
109 * <p>
110 * ...could be collapsed to...
111 * <p class='bcode'>
112 *    Via: 1.0 ricky, 1.1 mertz, 1.0 lucy
113 * </p>
114 *
115 * <p>
116 * Applications SHOULD NOT combine multiple entries unless they are all under the same organizational control and the
117 * hosts have already been replaced by pseudonyms.
118 * Applications MUST NOT combine entries which have different received-protocol values.
119 *
120 * <h5 class='section'>See Also:</h5><ul>
121 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
122 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
123 * </ul>
124 *
125 * @serial exclude
126 */
127@Header("Via")
128public class Via extends BasicCsvHeader {
129   private static final long serialVersionUID = 1L;
130   private static final String NAME = "Via";
131
132   /**
133    * Static creator.
134    *
135    * @param value
136    *    The header value.
137    *    <br>Can be <jk>null</jk>.
138    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
139    */
140   public static Via of(String value) {
141      return value == null ? null : new Via(value);
142   }
143
144   /**
145    * Static creator.
146    *
147    * @param value
148    *    The header value.
149    *    <br>Can be <jk>null</jk>.
150    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
151    */
152   public static Via of(String...value) {
153      return value == null ? null : new Via(value);
154   }
155
156   /**
157    * Static creator with delayed value.
158    *
159    * <p>
160    * Header value is re-evaluated on each call to {@link #getValue()}.
161    *
162    * @param value
163    *    The supplier of the header value.
164    *    <br>Can be <jk>null</jk>.
165    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
166    */
167   public static Via of(Supplier<String[]> value) {
168      return value == null ? null : new Via(value);
169   }
170
171   /**
172    * Constructor.
173    *
174    * @param value
175    *    The header value.
176    *    <br>Can be <jk>null</jk>.
177    */
178   public Via(String value) {
179      super(NAME, value);
180   }
181
182   /**
183    * Constructor.
184    *
185    * @param value
186    *    The header value.
187    *    <br>Can be <jk>null</jk>.
188    */
189   public Via(String...value) {
190      super(NAME, value);
191   }
192
193   /**
194    * Constructor with delayed value.
195    *
196    * <p>
197    * Header value is re-evaluated on each call to {@link #getValue()}.
198    *
199    * @param value
200    *    The supplier of the header value.
201    *    <br>Can be <jk>null</jk>.
202    */
203   public Via(Supplier<String[]> value) {
204      super(NAME, value);
205   }
206}