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:
parent
614b9e0f25
commit
0db652277f
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user