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;
014
015/**
016 * Represents a parsed <l>Via</l> HTTP response header.
017 * 
018 * <p>
019 * Informs the client of proxies through which the response was sent.
020 * 
021 * <h5 class='figure'>Example</h5>
022 * <p class='bcode'>
023 *    Via: 1.0 fred, 1.1 example.com (Apache/1.1)
024 * </p>
025 * 
026 * <p>
027 * Informs the client of proxies through which the response was sent.
028 * 
029 * <p>
030 * <h5 class='figure'>Example</h5>
031 * <p class='bcode'>
032 *    Via: 1.0 fred, 1.1 example.com (Apache/1.1)
033 * </p>
034 * 
035 * <p>
036 * <h5 class='topic'>RFC2616 Specification</h5>
037 * 
038 * The Via general-header field MUST be used by gateways and proxies to indicate the intermediate protocols and
039 * recipients between the user agent and the server on requests, and between the origin server and the client on
040 * responses.
041 * It is analogous to the "Received" field of RFC 822 and is intended to be used for tracking message forwards,
042 * avoiding request loops, and identifying the protocol capabilities of all senders along the request/response chain.
043 * 
044 * <p class='bcode'>
045 *    Via =  "Via" ":" 1#( received-protocol received-by [ comment ] )
046 *    received-protocol = [ protocol-name "/" ] protocol-version
047 *    protocol-name     = token
048 *    protocol-version  = token
049 *    received-by       = ( host [ ":" port ] ) | pseudonym
050 *    pseudonym         = token
051 * </p>
052 * 
053 * <p>
054 * The received-protocol indicates the protocol version of the message received by the server or client along each
055 * segment of the request/response chain.
056 * The received-protocol version is appended to the Via field value when the message is forwarded so that information
057 * about the protocol capabilities of upstream applications remains visible to all recipients.
058 * 
059 * <p>
060 * The protocol-name is optional if and only if it would be "HTTP".
061 * The received-by field is normally the host and optional port number of a recipient server or client that subsequently
062 * forwarded the message.
063 * However, if the real host is considered to be sensitive information, it MAY be replaced by a pseudonym.
064 * If the port is not given, it MAY be assumed to be the default port of the received-protocol.
065 * 
066 * <p>
067 * Multiple Via field values represents each proxy or gateway that has forwarded the message.
068 * Each recipient MUST append its information such that the end result is ordered according to the sequence of
069 * forwarding applications.
070 * 
071 * <p>
072 * Comments MAY be used in the Via header field to identify the software of the recipient proxy or gateway, analogous
073 * to the User-Agent and Server header fields.
074 * However, all comments in the Via field are optional and MAY be removed by any recipient prior to forwarding the
075 * message.
076 * 
077 * <p>
078 * For example, a request message could be sent from an HTTP/1.0 user agent to an internal proxy code-named "fred",
079 * which uses HTTP/1.1 to forward the request to a public proxy at nowhere.com, which completes the request by
080 * forwarding it to the origin server at www.ics.uci.edu.
081 * The request received by www.ics.uci.edu would then have the following Via header field:
082 * <p class='bcode'>
083 *    Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
084 * </p>
085 * 
086 * <p>
087 * Proxies and gateways used as a portal through a network firewall SHOULD NOT, by default, forward the names and ports
088 * of hosts within the firewall region.
089 * This information SHOULD only be propagated if explicitly enabled.
090 * If not enabled, the received-by host of any host behind the firewall SHOULD be replaced by an appropriate pseudonym
091 * for that host.
092 * 
093 * <p>
094 * For organizations that have strong privacy requirements for hiding internal structures, a proxy MAY combine an
095 * ordered subsequence of Via header field entries with identical received-protocol values into a single such entry.
096 * For example...
097 * <p class='bcode'>
098 *    Via: 1.0 ricky, 1.1 ethel, 1.1 fred, 1.0 lucy
099 * </p>
100 * 
101 * <p>
102 * ...could be collapsed to...
103 * <p class='bcode'>
104 *    Via: 1.0 ricky, 1.1 mertz, 1.0 lucy
105 * </p>
106 * 
107 * <p>
108 * Applications SHOULD NOT combine multiple entries unless they are all under the same organizational control and the
109 * hosts have already been replaced by pseudonyms.
110 * Applications MUST NOT combine entries which have different received-protocol values.
111 * 
112 * <h5 class='section'>See Also:</h5>
113 * <ul class='doctree'>
114 *    <li class='extlink'><a class='doclink' href='https://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a>
115 * </ul>
116 */
117public final class Via extends HeaderStringArray {
118
119   /**
120    * Returns a parsed <code>Via</code> header.
121    * 
122    * @param value The <code>Via</code> header string.
123    * @return The parsed <code>Via</code> header, or <jk>null</jk> if the string was null.
124    */
125   public static Via forString(String value) {
126      if (value == null)
127         return null;
128      return new Via(value);
129   }
130
131   private Via(String value) {
132      super(value);
133   }
134}