DefaultHttp2Headers#contains(CharSequence, CharSequence) does not work with String

Motivation:

If you test a header value providing a String, contains() returns false.
This is due to the implementation inherited from DefaultHeaders using
the JAVA_HASHER.

JAVA_HASHER.equals returns false because a is a String and b an
AsciiString.

Modifications:

DefaultHttp2Headers overrides contains and uses CASE_SENSITIVE_HASHER.

Result:

You can test a header value with any CharSequence implementation.
This commit is contained in:
Thomas Segismont 2018-01-26 16:57:40 +01:00 committed by Norman Maurer
parent 614b9e0f25
commit 0db652277f
2 changed files with 9 additions and 2 deletions

View File

@ -183,6 +183,11 @@ public class DefaultHttp2Headers
return get(PseudoHeaderName.STATUS.value());
}
@Override
public boolean contains(CharSequence name, CharSequence value) {
return contains(name, value, false);
}
@Override
public boolean contains(CharSequence name, CharSequence value, boolean caseInsensitive) {
return contains(name, value, caseInsensitive ? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER);

View File

@ -146,8 +146,10 @@ public class DefaultHttp2HeadersTest {
@Test
public void testContainsNameAndValue() {
Http2Headers headers = newHeaders();
assertFalse(headers.contains("name1", "Value2", false));
assertTrue(headers.contains("name1", "Value2", true));
assertTrue(headers.contains("name1", "value2"));
assertFalse(headers.contains("name1", "Value2"));
assertTrue(headers.contains("2name", "Value3", true));
assertFalse(headers.contains("2name", "Value3", false));
}
private static void verifyAllPseudoHeadersPresent(Http2Headers headers) {