1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.apache.commons.httpclient;
32
33 /***
34 * <p>An HTTP header.</p>
35 *
36 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
37 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
38 * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
39 * @version $Revision$ $Date$
40 */
41 public class Header extends NameValuePair {
42
43
44
45 /***
46 * Autogenerated header flag.
47 */
48 private boolean isAutogenerated = false;
49
50 /***
51 * Default constructor.
52 */
53 public Header() {
54 this(null, null);
55 }
56
57 /***
58 * Constructor with name and value
59 *
60 * @param name the header name
61 * @param value the header value
62 */
63 public Header(String name, String value) {
64 super(name, value);
65 }
66
67 /***
68 * Constructor with name and value
69 *
70 * @param name the header name
71 * @param value the header value
72 * @param isAutogenerated <tt>true</tt> if the header is autogenerated,
73 * <tt>false</tt> otherwise.
74 *
75 * @since 3.0
76 */
77 public Header(String name, String value, boolean isAutogenerated) {
78 super(name, value);
79 this.isAutogenerated = isAutogenerated;
80 }
81
82
83
84 /***
85 * Returns a {@link String} representation of the header.
86 *
87 * @return stringHEAD
88 */
89 public String toExternalForm() {
90 return ((null == getName() ? "" : getName())
91 + ": "
92 + (null == getValue() ? "" : getValue())
93 + "\r\n");
94 }
95
96 /***
97 * Returns a {@link String} representation of the header.
98 *
99 * @return stringHEAD
100 */
101 public String toString() {
102 return toExternalForm();
103 }
104
105 /***
106 * Returns an array of {@link HeaderElement}s
107 * constructed from my value.
108 *
109 * @see HeaderElement#parse
110 * @throws HttpException if the header cannot be parsed
111 * @return an array of header elements
112 *
113 * @deprecated Use #getElements
114 */
115 public HeaderElement[] getValues() throws HttpException {
116 return HeaderElement.parse(getValue());
117 }
118
119 /***
120 * Returns an array of {@link HeaderElement}s
121 * constructed from my value.
122 *
123 * @see HeaderElement#parseElements(String)
124 *
125 * @return an array of header elements
126 *
127 * @since 3.0
128 */
129 public HeaderElement[] getElements() {
130 return HeaderElement.parseElements(getValue());
131 }
132
133 /***
134 * Returns the value of the auto-generated header flag.
135 *
136 * @return <tt>true</tt> if the header is autogenerated,
137 * <tt>false</tt> otherwise.
138 *
139 * @since 3.0
140 */
141 public boolean isAutogenerated() {
142 return isAutogenerated;
143 }
144
145 }