8000 Save HTTP 2 pseudo-header lower-case validation (#13765) · netty/netty@3b81f2c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b81f2c

Browse files
authored
Save HTTP 2 pseudo-header lower-case validation (#13765)
Motivation: pseudo-header constants doesn't requires any further validation Modifications: anticipate pseudoheader lookup on http 2 header name validation, saving any further validation, if positive Result: Faster validations over known pseudo-headers
1 parent ce0366b commit 3b81f2c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
2626
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
27-
import static io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName.getPseudoHeader;
2827
import static io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName.hasPseudoHeaderFormat;
28+
import static io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName.isPseudoHeader;
2929
import static io.netty.util.AsciiString.CASE_INSENSITIVE_HASHER;
3030
import static io.netty.util.AsciiString.CASE_SENSITIVE_HASHER;
3131
import static io.netty.util.AsciiString.isUpperCase;
@@ -47,6 +47,15 @@ public void validateName(CharSequence name) {
4747
"empty headers are not allowed [%s]", name));
4848
}
4949

50+
if (hasPseudoHeaderFormat(name)) {
51+
if (!isPseudoHeader(name)) {
52+
PlatformDependent.throwException(connectionError(
53+
PROTOCOL_ERROR, "Invalid HTTP/2 pseudo-header '%s' encountered.", name));
54+
}
55+
// no need for lower-case validation, we trust our own pseudo header constants
56+
return;
57+
}
58+
5059
if (name instanceof AsciiString) {
5160
final int index;
5261
try {
@@ -72,14 +81,6 @@ public void validateName(CharSequence name) {
7281
}
7382
}
7483
}
75-
76-
if (hasPseudoHeaderFormat(name)) {
77-
final Http2Headers.PseudoHeaderName pseudoHeader = getPseudoHeader(name);
78-
if (pseudoHeader == null) {
79-
PlatformDependent.throwException(connectionError(
80-
PROTOCOL_ERROR, "Invalid HTTP/2 pseudo-header '%s' encountered.", name));
81-
}
82-
}
8384
}
8485
};
8586

0 commit comments

Comments
 (0)
0