Skip to content

Commit

Permalink
HTTP/2 Make DefaultHttp2HeadersDecoder's Http2Headers object creation…
Browse files Browse the repository at this point in the history
… extensible

Motivation:
It is generally useful to override DefaultHttp2HeadersDecoder's creation of a new Http2Headers object so more optimized versions can be substituted if the use case allows for it.

Modifications:
- DefaultHttp2HeadersDecoder should support an overridable method to generate the new Http2Headers object for each decode operation

Result:
DefaultHttp2HeadersDecoder is more extensible.
Fixes netty#6591.
  • Loading branch information
Scottmitch authored and kiril-me committed Feb 28, 2018
1 parent d6597b9 commit 765c59e
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Configuration configuration() {
@Override
public Http2Headers decodeHeaders(int streamId, ByteBuf headerBlock) throws Http2Exception {
try {
final Http2Headers headers = new DefaultHttp2Headers(validateHeaders, (int) headerArraySizeAccumulator);
final Http2Headers headers = newHeaders();
hpackDecoder.decode(streamId, headerBlock, headers);
headerArraySizeAccumulator = HEADERS_COUNT_WEIGHT_NEW * headers.size() +
HEADERS_COUNT_WEIGHT_HISTORICAL * headerArraySizeAccumulator;
Expand All @@ -126,4 +126,28 @@ public Http2Headers decodeHeaders(int streamId, ByteBuf headerBlock) throws Http
throw connectionError(COMPRESSION_ERROR, e, e.getMessage());
}
}

/**
* A weighted moving average estimating how many headers are expected during the decode process.
* @return an estimate of how many headers are expected during the decode process.
*/
protected final int numberOfHeadersGuess() {
return (int) headerArraySizeAccumulator;
}

/**
* Determines if the headers should be validated as a result of the decode operation.
* @return {@code true} if the headers should be validated as a result of the decode operation.
*/
protected final boolean validateHeaders() {
return validateHeaders;
}

/**
* Create a new {@link Http2Headers} object which will store the results of the decode operation.
* @return a new {@link Http2Headers} object which will store the results of the decode operation.
*/
protected Http2Headers newHeaders() {
return new DefaultHttp2Headers(validateHeaders, (int) headerArraySizeAccumulator);
}
}

0 comments on commit 765c59e

Please sign in to comment.