1 /* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java $ 3 * $Revision: 652956 $ 4 * $Date: 2008-05-02 17:13:05 -0700 (Fri, 02 May 2008) $ 5 * 6 * ==================================================================== 7 * Licensed to the Apache Software Foundation (ASF) under one 8 * or more contributor license agreements. See the NOTICE file 9 * distributed with this work for additional information 10 * regarding copyright ownership. The ASF licenses this file 11 * to you under the Apache License, Version 2.0 (the 12 * "License"); you may not use this file except in compliance 13 * with the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, 18 * software distributed under the License is distributed on an 19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 * KIND, either express or implied. See the License for the 21 * specific language governing permissions and limitations 22 * under the License. 23 * ==================================================================== 24 * 25 * This software consists of voluntary contributions made by many 26 * individuals on behalf of the Apache Software Foundation. For more 27 * information on the Apache Software Foundation, please see 28 * <http://www.apache.org/>. 29 * 30 */ 31 32 package org.apache.http.message; 33 34 import org.apache.http.Header; 35 import org.apache.http.HeaderElement; 36 import org.apache.http.ParseException; 37 38 /** 39 * Represents an HTTP header field. 40 * 41 * <p>The HTTP header fields follow the same generic format as 42 * that given in Section 3.1 of RFC 822. Each header field consists 43 * of a name followed by a colon (":") and the field value. Field names 44 * are case-insensitive. The field value MAY be preceded by any amount 45 * of LWS, though a single SP is preferred. 46 * 47 *<pre> 48 * message-header = field-name ":" [ field-value ] 49 * field-name = token 50 * field-value = *( field-content | LWS ) 51 * field-content = <the OCTETs making up the field-value 52 * and consisting of either *TEXT or combinations 53 * of token, separators, and quoted-string> 54 *</pre> 55 * 56 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a> 57 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> 58 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> 59 * 60 * 61 * <!-- empty lines above to avoid 'svn diff' context problems --> 62 * @version $Revision: 652956 $ $Date: 2008-05-02 17:13:05 -0700 (Fri, 02 May 2008) $ 63 * 64 * @since 4.0 65 * 66 * @deprecated Please use {@link java.net.URL#openConnection} instead. 67 * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 68 * for further details. 69 */ 70 @Deprecated 71 public class BasicHeader implements Header, Cloneable { 72 73 /** 74 * Header name. 75 */ 76 private final String name; 77 78 /** 79 * Header value. 80 */ 81 private final String value; 82 83 /** 84 * Constructor with name and value 85 * 86 * @param name the header name 87 * @param value the header value 88 */ BasicHeader(final String name, final String value)89 public BasicHeader(final String name, final String value) { 90 super(); 91 if (name == null) { 92 throw new IllegalArgumentException("Name may not be null"); 93 } 94 this.name = name; 95 this.value = value; 96 } 97 98 /** 99 * Returns the header name. 100 * 101 * @return String name The name 102 */ getName()103 public String getName() { 104 return this.name; 105 } 106 107 /** 108 * Returns the header value. 109 * 110 * @return String value The current value. 111 */ getValue()112 public String getValue() { 113 return this.value; 114 } 115 116 /** 117 * Returns a {@link String} representation of the header. 118 * 119 * @return a string 120 */ toString()121 public String toString() { 122 // no need for non-default formatting in toString() 123 return BasicLineFormatter.DEFAULT.formatHeader(null, this).toString(); 124 } 125 126 /** 127 * Returns an array of {@link HeaderElement}s constructed from my value. 128 * 129 * @see BasicHeaderValueParser#parseElements(String, HeaderValueParser) 130 * 131 * @return an array of header elements 132 * 133 * @throws ParseException in case of a parse error 134 */ getElements()135 public HeaderElement[] getElements() throws ParseException { 136 if (this.value != null) { 137 // result intentionally not cached, it's probably not used again 138 return BasicHeaderValueParser.parseElements(this.value, null); 139 } else { 140 return new HeaderElement[] {}; 141 } 142 } 143 clone()144 public Object clone() throws CloneNotSupportedException { 145 return super.clone(); 146 } 147 148 } 149