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