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 package org.apache.hc.core5.http.message;
29
30 import java.io.Serializable;
31 import java.util.Objects;
32
33 import org.apache.hc.core5.annotation.Contract;
34 import org.apache.hc.core5.annotation.ThreadingBehavior;
35 import org.apache.hc.core5.http.Header;
36 import org.apache.hc.core5.util.Args;
37
38
39
40
41
42
43 @Contract(threading = ThreadingBehavior.IMMUTABLE)
44 public class BasicHeader implements Header, Cloneable, Serializable {
45
46 private static final long serialVersionUID = -5427236326487562174L;
47
48 private final String name;
49 private final boolean sensitive;
50 private final String value;
51
52
53
54
55
56
57
58 public BasicHeader(final String name, final Object value) {
59 this(name, value, false);
60 }
61
62
63
64
65
66
67
68
69
70
71 public BasicHeader(final String name, final Object value, final boolean sensitive) {
72 super();
73 this.name = Args.notNull(name, "Name");
74 this.value = Objects.toString(value, null);
75 this.sensitive = sensitive;
76 }
77
78 @Override
79 public String getName() {
80 return name;
81 }
82
83 @Override
84 public String getValue() {
85 return value;
86 }
87
88 @Override
89 public boolean isSensitive() {
90 return this.sensitive;
91 }
92
93 @Override
94 public String toString() {
95 final StringBuilder buf = new StringBuilder();
96 buf.append(this.getName()).append(": ");
97 if (this.getValue() != null) {
98 buf.append(this.getValue());
99 }
100 return buf.toString();
101 }
102
103 }