Skip to content

Commit 6abc8da

Browse files
garydgregoryok2c
authored andcommitted
HTTPCORE-499 Make interface Header extend NameValuePair.
1 parent 1c4729b commit 6abc8da

File tree

4 files changed

+36
-57
lines changed

4 files changed

+36
-57
lines changed

RELEASE_NOTES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Changelog
77
* HTTPCORE-496: Add API org.apache.http.protocol.UriPatternMatcher.entrySet().
88
Contributed by Gary Gregory <ggregory at apache.org>
99

10+
* HTTPCORE-499 Make interface Header extend NameValuePair
11+
Contributed by Gary Gregory <ggregory at apache.org>
12+
1013

1114
Release 5.0-BETA1
1215
-------------------

httpcore5/src/main/java/org/apache/hc/core5/http/Header.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,21 @@
2828
package org.apache.hc.core5.http;
2929

3030
/**
31-
* Represents an HTTP header field consisting of a field name and a field value..
31+
* Represents an HTTP header field consisting of a field name and a field
32+
* value.
3233
*
3334
* @since 4.0
3435
*/
35-
public interface Header {
36-
37-
/**
38-
* Get the name of the Header.
39-
*
40-
* @return the name of the Header, never {@code null}
41-
*/
42-
String getName();
43-
44-
/**
45-
* Get the value of the Header.
46-
*
47-
* @return the value of the Header, may be {@code null}
48-
*/
49-
String getValue();
36+
public interface Header extends NameValuePair {
5037

5138
/**
5239
* Returns {@code true} if the header should be considered sensitive.
5340
* <p>
5441
* Some encoding schemes such as HPACK impose restrictions on encoded
5542
* representation of sensitive headers.
43+
* </p>
44+
*
45+
* @return {@code true} if the header should be considered sensitive.
5646
*
5747
* @since 5.0
5848
*/

httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,23 @@
2727

2828
package org.apache.hc.core5.http.message;
2929

30-
import java.io.Serializable;
31-
import java.util.Locale;
3230
import java.util.Objects;
3331

3432
import org.apache.hc.core5.annotation.Contract;
3533
import org.apache.hc.core5.annotation.ThreadingBehavior;
3634
import org.apache.hc.core5.http.Header;
3735
import org.apache.hc.core5.util.Args;
38-
import org.apache.hc.core5.util.LangUtils;
3936

4037
/**
4138
* Immutable {@link Header}.
4239
*
4340
* @since 4.0
4441
*/
4542
@Contract(threading = ThreadingBehavior.IMMUTABLE)
46-
public class BasicHeader implements Header, Serializable {
43+
public class BasicHeader extends BasicNameValuePair implements Header {
4744

4845
private static final long serialVersionUID = -5427236326487562174L;
4946

50-
private final String name;
51-
private final String value;
5247
private final boolean sensitive;
5348

5449
/**
@@ -61,9 +56,7 @@ public class BasicHeader implements Header, Serializable {
6156
* @since 5.0
6257
*/
6358
public BasicHeader(final String name, final Object value, final boolean sensitive) {
64-
super();
65-
this.name = Args.notNull(name, "Name");
66-
this.value = Objects.toString(value, null);
59+
super(Args.notNull(name, "Name"), Objects.toString(value, null));
6760
this.sensitive = sensitive;
6861
}
6962

@@ -77,16 +70,6 @@ public BasicHeader(final String name, final Object value) {
7770
this(name, value, false);
7871
}
7972

80-
@Override
81-
public String getName() {
82-
return this.name;
83-
}
84-
85-
@Override
86-
public String getValue() {
87-
return this.value;
88-
}
89-
9073
@Override
9174
public boolean isSensitive() {
9275
return this.sensitive;
@@ -95,30 +78,11 @@ public boolean isSensitive() {
9578
@Override
9679
public String toString() {
9780
final StringBuilder buf = new StringBuilder();
98-
buf.append(this.name).append(": ");
99-
if (this.value != null) {
100-
buf.append(this.value);
81+
buf.append(this.getName()).append(": ");
82+
if (this.getValue() != null) {
83+
buf.append(this.getValue());
10184
}
10285
return buf.toString();
10386
}
10487

105-
@Override
106-
public boolean equals(final Object obj) {
107-
if (this == obj) {
108-
return true;
109-
}
110-
if (obj instanceof BasicHeader) {
111-
final BasicHeader that = (BasicHeader) obj;
112-
return this.name.equalsIgnoreCase(that.name) && LangUtils.equals(this.value, that.value);
113-
}
114-
return false;
115-
}
116-
117-
@Override
118-
public int hashCode() {
119-
int hash = LangUtils.HASH_SEED;
120-
hash = LangUtils.hashCode(hash, this.name.toLowerCase(Locale.ROOT));
121-
hash = LangUtils.hashCode(hash, this.value);
122-
return hash;
123-
}
12488
}

httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
package org.apache.hc.core5.http.message;
2929

3030
import java.io.Serializable;
31+
import java.util.Locale;
3132

3233
import org.apache.hc.core5.annotation.Contract;
3334
import org.apache.hc.core5.annotation.ThreadingBehavior;
3435
import org.apache.hc.core5.http.NameValuePair;
3536
import org.apache.hc.core5.util.Args;
37+
import org.apache.hc.core5.util.LangUtils;
3638

3739
/**
3840
* Basic implementation of {@link NameValuePair}.
@@ -84,4 +86,24 @@ public String toString() {
8486
return buffer.toString();
8587
}
8688

89+
@Override
90+
public boolean equals(final Object obj) {
91+
if (this == obj) {
92+
return true;
93+
}
94+
if (obj instanceof BasicNameValuePair) {
95+
final BasicNameValuePair that = (BasicNameValuePair) obj;
96+
return this.name.equalsIgnoreCase(that.name) && LangUtils.equals(this.value, that.value);
97+
}
98+
return false;
99+
}
100+
101+
@Override
102+
public int hashCode() {
103+
int hash = LangUtils.HASH_SEED;
104+
hash = LangUtils.hashCode(hash, this.name.toLowerCase(Locale.ROOT));
105+
hash = LangUtils.hashCode(hash, this.value);
106+
return hash;
107+
}
108+
87109
}

0 commit comments

Comments
 (0)