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.annotation.*;
016import org.apache.juneau.http.annotation.*;
017
018/**
019 * Represents a parsed <l>Connection</l> HTTP request header.
020 *
021 * <p>
022 * Control options for the current connection and list of hop-by-hop request fields.
023 *
024 * <h5 class='figure'>Example</h5>
025 * <p class='bcode w800'>
026 *    Connection: keep-alive
027 *    Connection: Upgrade
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The Connection general-header field allows the sender to specify options that are desired for that particular
033 * connection and MUST NOT be communicated by proxies over further connections.
034 *
035 * <p>
036 * The Connection header has the following grammar:
037 * <p class='bcode w800'>
038 *    Connection = "Connection" ":" 1#(connection-token)
039 *    connection-token  = token
040 * </p>
041 *
042 * <p>
043 * HTTP/1.1 proxies MUST parse the Connection header field before a message is forwarded and, for each connection-token
044 * in this field, remove any header field(s) from the message with the same name as the connection-token.
045 * Connection options are signaled by the presence of a connection-token in the Connection header field, not by any
046 * corresponding additional header field(s), since the additional header field may not be sent if there are no
047 * parameters associated with that connection option.
048 *
049 * <p>
050 * Message headers listed in the Connection header MUST NOT include end-to-end headers, such as Cache-Control.
051 *
052 * <p>
053 * HTTP/1.1 defines the "close" connection option for the sender to signal that the connection will be closed after
054 * completion of the response.
055 * For example...
056 * <p class='bcode w800'>
057 *    Connection: close
058 * </p>
059 * <p>
060 * ...in either the request or the response header fields indicates that the connection SHOULD NOT be considered
061 * `persistent' (section 8.1) after the current request/response is complete.
062 *
063 * <p>
064 * HTTP/1.1 applications that do not support persistent connections MUST include the "close" connection option in
065 * every message.
066 *
067 * <p>
068 * A system receiving an HTTP/1.0 (or lower-version) message that includes a Connection header MUST, for each
069 * connection-token in this field, remove and ignore any header field(s) from the message with the same name as the
070 * connection-token.
071 * This protects against mistaken forwarding of such header fields by pre-HTTP/1.1 proxies.
072 * See section 19.6.2.
073 *
074 * <h5 class='section'>See Also:</h5>
075 * <ul class='doctree'>
076 *    <li class='extlink'>{@doc RFC2616}
077 * </ul>
078 */
079@Header("Connection")
080@BeanIgnore
081public final class Connection extends HeaderString {
082
083   /**
084    * Returns a parsed <code>Connection</code> header.
085    *
086    * @param value The <code>Connection</code> header string.
087    * @return The parsed <code>Connection</code> header, or <jk>null</jk> if the string was null.
088    */
089   public static Connection forString(String value) {
090      if (value == null)
091         return null;
092      return new Connection(value);
093   }
094
095
096   private Connection(String value) {
097      super(value);
098   }
099
100   /**
101    * Returns <jk>true</jk> if the header value is <code>close</code>.
102    *
103    * @return <jk>true</jk> if the header value is <code>close</code>.
104    */
105   public boolean isClose() {
106      return eqIC("close");
107   }
108
109   /**
110    * Returns <jk>true</jk> if the header value is <code>keep-alive</code>.
111    *
112    * @return <jk>true</jk> if the header value is <code>keep-alive</code>.
113    */
114   public boolean isKeepAlive() {
115      return eqIC("keep-alive");
116   }
117
118   /**
119    * Returns <jk>true</jk> if the header value is <code>upgrade</code>.
120    *
121    * @return <jk>true</jk> if the header value is <code>upgrade</code>.
122    */
123   public boolean isUpgrade() {
124      return eqIC("upgrade");
125   }
126}