Skip to content

Commit

Permalink
Save HTTP 2 pseudo-header lower-case validation (#13765)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
franz1981 committed Jan 12, 2024
1 parent ce0366b commit 3b81f2c
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
import static io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName.getPseudoHeader;
import static io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName.hasPseudoHeaderFormat;
import static io.netty.handler.codec.http2.Http2Headers.PseudoHeaderName.isPseudoHeader;
import static io.netty.util.AsciiString.CASE_INSENSITIVE_HASHER;
import static io.netty.util.AsciiString.CASE_SENSITIVE_HASHER;
import static io.netty.util.AsciiString.isUpperCase;
Expand All @@ -47,6 +47,15 @@ public void validateName(CharSequence name) {
"empty headers are not allowed [%s]", name));
}

if (hasPseudoHeaderFormat(name)) {
if (!isPseudoHeader(name)) {
PlatformDependent.throwException(connectionError(
PROTOCOL_ERROR, "Invalid HTTP/2 pseudo-header '%s' encountered.", name));
}
// no need for lower-case validation, we trust our own pseudo header constants
return;
}

if (name instanceof AsciiString) {
final int index;
try {
Expand All @@ -72,14 +81,6 @@ public void validateName(CharSequence name) {
}
}
}

if (hasPseudoHeaderFormat(name)) {
final Http2Headers.PseudoHeaderName pseudoHeader = getPseudoHeader(name);
if (pseudoHeader == null) {
PlatformDependent.throwException(connectionError(
PROTOCOL_ERROR, "Invalid HTTP/2 pseudo-header '%s' encountered.", name));
}
}
}
};

Expand Down

0 comments on commit 3b81f2c

Please sign in to comment.