Skip to content

Commit 7f23c34

Browse files
tsegismontnormanmaurer
authored andcommitted
ReadOnlyHttp2Headers.contains always ignores case for values
Motivation: When checking if a value is present, ReadOnlyHttp2Headers always ignores case for values. RFC 7540 says: https://tools.ietf.org/html/rfc7540#section-8.1.2 "header field names are strings of ASCII characters that are compared in a case-insensitive fashion" But there is no such constraint on header values Modifications: Updated ReadOnlyHttp2Headers.contains to compare header value in a case-sensitive way. Result: ReadOnlyHttp2Headers compares header names in a case-insensitive way, values in a case-sensitive way.
1 parent 0db6522 commit 7f23c34

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

codec-http2/src/main/java/io/netty/handler/codec/http2/ReadOnlyHttp2Headers.java

+1-23
Original file line numberDiff line numberDiff line change
@@ -430,29 +430,7 @@ public boolean contains(CharSequence name) {
430430

431431
@Override
432432
public boolean contains(CharSequence name, CharSequence value) {
433-
final int nameHash = AsciiString.hashCode(name);
434-
final int valueHash = AsciiString.hashCode(value);
435-
436-
final int pseudoHeadersEnd = pseudoHeaders.length - 1;
437-
for (int i = 0; i < pseudoHeadersEnd; i += 2) {
438-
AsciiString roName = pseudoHeaders[i];
439-
AsciiString roValue = pseudoHeaders[i + 1];
440-
if (roName.hashCode() == nameHash && roValue.hashCode() == valueHash &&
441-
roName.contentEqualsIgnoreCase(name) && roValue.contentEqualsIgnoreCase(value)) {
442-
return true;
443-
}
444-
}
445-
446-
final int otherHeadersEnd = otherHeaders.length - 1;
447-
for (int i = 0; i < otherHeadersEnd; i += 2) {
448-
AsciiString roName = otherHeaders[i];
449-
AsciiString roValue = otherHeaders[i + 1];
450-
if (roName.hashCode() == nameHash && roValue.hashCode() == valueHash &&
451-
roName.contentEqualsIgnoreCase(name) && roValue.contentEqualsIgnoreCase(value)) {
452-
return true;
453-
}
454-
}
455-
return false;
433+
return contains(name, value, false);
456434
}
457435

458436
@Override

codec-http2/src/test/java/io/netty/handler/codec/http2/ReadOnlyHttp2HeadersTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ public void testContainsName() {
136136
public void testContainsNameAndValue() {
137137
Http2Headers headers = newClientHeaders();
138138
assertTrue(headers.contains("Name1", "value1"));
139-
assertFalse(headers.contains("Name1", "Value1", false));
140-
assertTrue(headers.contains("Name1", "Value1", true));
139+
assertFalse(headers.contains("Name1", "Value1"));
140+
assertTrue(headers.contains("name2", "Value2", true));
141+
assertFalse(headers.contains("name2", "Value2", false));
141142
assertTrue(headers.contains(Http2Headers.PseudoHeaderName.PATH.value(), "/foo"));
142143
assertFalse(headers.contains(Http2Headers.PseudoHeaderName.STATUS.value(), "200"));
143144
assertFalse(headers.contains("a missing header", "a missing value"));

0 commit comments

Comments
 (0)