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>Upgrade</l> HTTP request header.
019 *
020 * <p>
021 * Ask the client to upgrade to another protocol.
022 *
023 * <h5 class='figure'>Example</h5>
024 * <p class='bcode w800'>
025 *    Upgrade: HTTP/2.0, HTTPS/1.3, IRC/6.9, RTA/x11, websocket
026 * </p>
027 *
028 * <h5 class='topic'>RFC2616 Specification</h5>
029 *
030 * The Upgrade general-header allows the client to specify what additional communication protocols it supports and
031 * would like to use if the server finds it appropriate to switch protocols.
032 * The server MUST use the Upgrade header field within a 101 (Switching Protocols) response to indicate which
033 * protocol(s) are being switched.
034 *
035 * <p class='bcode w800'>
036 *    Upgrade        = "Upgrade" ":" 1#product
037 * </p>
038 *
039 * <p>
040 * For example,
041 * <p class='bcode w800'>
042 *    Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
043 * </p>
044 *
045 * <p>
046 * The Upgrade header field is intended to provide a simple mechanism for transition from HTTP/1.1 to some other,
047 * incompatible protocol.
048 * It does so by allowing the client to advertise its desire to use another protocol, such as a later version of HTTP
049 * with a higher major version number, even though the current request has been made using HTTP/1.1.
050 * This eases the difficult transition between incompatible protocols by allowing the client to initiate a request in
051 * the more commonly supported protocol while indicating to the server that it would like to use a "better" protocol if
052 * available (where "better" is determined by the server, possibly according to the nature of the method and/or resource
053 * being requested).
054 *
055 * <p>
056 * The Upgrade header field only applies to switching application-layer protocols upon the existing transport-layer
057 * connection.
058 * Upgrade cannot be used to insist on a protocol change; its acceptance and use by the server is optional.
059 * The capabilities and nature of the application-layer communication after the protocol change is entirely dependent
060 * upon the new protocol chosen, although the first action after changing the protocol MUST be a response to the initial
061 * HTTP request containing the Upgrade header field.
062 *
063 * <p>
064 * The Upgrade header field only applies to the immediate connection.
065 * Therefore, the upgrade keyword MUST be supplied within a Connection header field (section 14.10) whenever Upgrade is
066 * present in an HTTP/1.1 message.
067 *
068 * <p>
069 * The Upgrade header field cannot be used to indicate a switch to a protocol on a different connection.
070 * For that purpose, it is more appropriate to use a 301, 302, 303, or 305 redirection response.
071 *
072 * <p>
073 * This specification only defines the protocol name "HTTP" for use by the family of Hypertext Transfer Protocols, as
074 * defined by the HTTP version rules of section 3.1 and future updates to this specification.
075 * Any token can be used as a protocol name; however, it will only be useful if both the client and server associate
076 * the name with the same protocol.
077 *
078 * <h5 class='section'>See Also:</h5>
079 * <ul class='doctree'>
080 *    <li class='extlink'>{@doc RFC2616}
081 * </ul>
082 */
083@Header("Upgrade")
084public final class Upgrade extends HeaderStringArray {
085
086   /**
087    * Constructor.
088    *
089    * @param value
090    */
091   public Upgrade(String[] value) {
092      super(value);
093   }
094
095   /**
096    * Returns a parsed <code>Upgrade</code> header.
097    *
098    * @param value The <code>Upgrade</code> header string.
099    * @return The parsed <code>Upgrade</code> header, or <jk>null</jk> if the string was null.
100    */
101   public static Upgrade forString(String value) {
102      if (value == null)
103         return null;
104      return new Upgrade(value);
105   }
106
107   private Upgrade(String value) {
108      super(value);
109   }
110}