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
32 package org.apache.commons.httpclient;
33
34 /***
35 * <p>An HTTP header.</p>
36 *
37 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
38 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
39 * @version $Revision: 1.10.2.3 $ $Date: 2004/02/22 18:21:13 $
40 */
41 public class Header extends NameValuePair {
42
43
44
45 /***
46 * Default constructor.
47 */
48 public Header() {
49 this(null, null);
50 }
51
52 /***
53 * Constructor with name and value
54 *
55 * @param name the header name
56 * @param value the header value
57 */
58 public Header(String name, String value) {
59 super(name, value);
60 }
61
62
63
64 /***
65 * Returns a {@link String} representation of the header in the form:
66 * <pre>
67 * Name: valueCRLF
68 * </pre>
69 * The string is terminated by CRLF.
70 *
71 * @return stringHEAD
72 */
73 public String toExternalForm() {
74 return ((null == getName() ? "" : getName())
75 + ": "
76 + (null == getValue() ? "" : getValue())
77 + "\r\n");
78 }
79
80 /***
81 * Returns a {@link String} representation of the header.
82 *
83 * @return stringHEAD
84 */
85 public String toString() {
86 return toExternalForm();
87 }
88
89 /***
90 * Returns an array of {@link HeaderElement}s
91 * constructed from my value.
92 *
93 * @see HeaderElement#parse
94 * @throws HttpException if the header cannot be parsed
95 * @return an array of header elements
96 */
97 public HeaderElement[] getValues() throws HttpException {
98 return HeaderElement.parse(getValue());
99 }
100
101 }