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