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 * <ul class='seealso'> 075 * <li class='extlink'>{@doc RFC2616} 076 * </ul> 077 */ 078@Header("Connection") 079@BeanIgnore 080public final class Connection extends HeaderString { 081 082 /** 083 * Returns a parsed <c>Connection</c> header. 084 * 085 * @param value The <c>Connection</c> header string. 086 * @return The parsed <c>Connection</c> header, or <jk>null</jk> if the string was null. 087 */ 088 public static Connection forString(String value) { 089 if (value == null) 090 return null; 091 return new Connection(value); 092 } 093 094 095 private Connection(String value) { 096 super(value); 097 } 098 099 /** 100 * Returns <jk>true</jk> if the header value is <c>close</c>. 101 * 102 * @return <jk>true</jk> if the header value is <c>close</c>. 103 */ 104 public boolean isClose() { 105 return eqIC("close"); 106 } 107 108 /** 109 * Returns <jk>true</jk> if the header value is <c>keep-alive</c>. 110 * 111 * @return <jk>true</jk> if the header value is <c>keep-alive</c>. 112 */ 113 public boolean isKeepAlive() { 114 return eqIC("keep-alive"); 115 } 116 117 /** 118 * Returns <jk>true</jk> if the header value is <c>upgrade</c>. 119 * 120 * @return <jk>true</jk> if the header value is <c>upgrade</c>. 121 */ 122 public boolean isUpgrade() { 123 return eqIC("upgrade"); 124 } 125}