Package io.netty.handler.codec.http2
Class DefaultHttp2HeadersDecoder
java.lang.Object
io.netty.handler.codec.http2.DefaultHttp2HeadersDecoder
- All Implemented Interfaces:
Http2HeadersDecoder
,Http2HeadersDecoder.Configuration
public class DefaultHttp2HeadersDecoder
extends Object
implements Http2HeadersDecoder, Http2HeadersDecoder.Configuration
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.handler.codec.http2.Http2HeadersDecoder
Http2HeadersDecoder.Configuration
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate float
Used to calculate an exponential moving average of header sizes to get an estimate of how large the data structure for storing headers should be.private static final float
private static final float
private final HpackDecoder
private long
private final boolean
private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultHttp2HeadersDecoder
(boolean validateHeaders) Create a new instance.DefaultHttp2HeadersDecoder
(boolean validateHeaders, boolean validateHeaderValues) Create a new instance.DefaultHttp2HeadersDecoder
(boolean validateHeaders, boolean validateHeaderValues, long maxHeaderListSize) Create a new instance.DefaultHttp2HeadersDecoder
(boolean validateHeaders, boolean validateHeaderValues, HpackDecoder hpackDecoder) Exposed for testing only! Default values used in the initial settings frame are overridden intentionally for testing but violate the RFC if used outside the scope of testing.DefaultHttp2HeadersDecoder
(boolean validateHeaders, long maxHeaderListSize) Create a new instance.DefaultHttp2HeadersDecoder
(boolean validateHeaders, long maxHeaderListSize, int initialHuffmanDecodeCapacity) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionGet theHttp2HeadersDecoder.Configuration
for thisHttp2HeadersDecoder
decodeHeaders
(int streamId, ByteBuf headerBlock) Decodes the given headers block and returns the headers.long
Represents the value for SETTINGS_MAX_HEADER_LIST_SIZE.void
maxHeaderListSize
(long max, long goAwayMax) Configure the maximum allowed size in bytes of each set of headers.long
Represents the upper bound in bytes for a set of headers before aGO_AWAY
should be sent.long
Represents the value for SETTINGS_HEADER_TABLE_SIZE.void
maxHeaderTableSize
(long max) Represents the value for SETTINGS_HEADER_TABLE_SIZE.protected Http2Headers
Create a newHttp2Headers
object which will store the results of the decode operation.protected final int
A weighted moving average estimating how many headers are expected during the decode process.protected final boolean
Determines if the headers should be validated as a result of the decode operation.protected boolean
Determines if the header values should be validated as a result of the decode operation.
-
Field Details
-
HEADERS_COUNT_WEIGHT_NEW
private static final float HEADERS_COUNT_WEIGHT_NEW- See Also:
-
HEADERS_COUNT_WEIGHT_HISTORICAL
private static final float HEADERS_COUNT_WEIGHT_HISTORICAL- See Also:
-
hpackDecoder
-
validateHeaders
private final boolean validateHeaders -
validateHeaderValues
private final boolean validateHeaderValues -
maxHeaderListSizeGoAway
private long maxHeaderListSizeGoAway -
headerArraySizeAccumulator
private float headerArraySizeAccumulatorUsed to calculate an exponential moving average of header sizes to get an estimate of how large the data structure for storing headers should be.
-
-
Constructor Details
-
DefaultHttp2HeadersDecoder
public DefaultHttp2HeadersDecoder() -
DefaultHttp2HeadersDecoder
public DefaultHttp2HeadersDecoder(boolean validateHeaders) Create a new instance.- Parameters:
validateHeaders
-true
to validate headers are valid according to the RFC.
-
DefaultHttp2HeadersDecoder
public DefaultHttp2HeadersDecoder(boolean validateHeaders, boolean validateHeaderValues) Create a new instance.- Parameters:
validateHeaders
-true
to validate headers are valid according to the RFC. This validates everything except header values.validateHeaderValues
-true
to validate that header values are valid according to the RFC. Since this is potentially expensive, it can be enabled separately fromvalidateHeaders
.
-
DefaultHttp2HeadersDecoder
public DefaultHttp2HeadersDecoder(boolean validateHeaders, long maxHeaderListSize) Create a new instance.- Parameters:
validateHeaders
-true
to validate headers are valid according to the RFC.maxHeaderListSize
- This is the only setting that can be configured before notifying the peer. This is because SETTINGS_MAX_HEADER_LIST_SIZE allows a lower than advertised limit from being enforced, and the default limit is unlimited (which is dangerous).
-
DefaultHttp2HeadersDecoder
public DefaultHttp2HeadersDecoder(boolean validateHeaders, boolean validateHeaderValues, long maxHeaderListSize) Create a new instance.- Parameters:
validateHeaders
-true
to validate headers are valid according to the RFC. This validates everything except header values.validateHeaderValues
-true
to validate that header values are valid according to the RFC. Since this is potentially expensive, it can be enabled separately fromvalidateHeaders
.maxHeaderListSize
- This is the only setting that can be configured before notifying the peer. This is because SETTINGS_MAX_HEADER_LIST_SIZE allows a lower than advertised limit from being enforced, and the default limit is unlimited (which is dangerous).
-
DefaultHttp2HeadersDecoder
public DefaultHttp2HeadersDecoder(boolean validateHeaders, long maxHeaderListSize, @Deprecated int initialHuffmanDecodeCapacity) Create a new instance.- Parameters:
validateHeaders
-true
to validate headers are valid according to the RFC. This validates everything except header values.maxHeaderListSize
- This is the only setting that can be configured before notifying the peer. This is because SETTINGS_MAX_HEADER_LIST_SIZE allows a lower than advertised limit from being enforced, and the default limit is unlimited (which is dangerous).initialHuffmanDecodeCapacity
- Does nothing, do not use.
-
DefaultHttp2HeadersDecoder
DefaultHttp2HeadersDecoder(boolean validateHeaders, boolean validateHeaderValues, HpackDecoder hpackDecoder) Exposed for testing only! Default values used in the initial settings frame are overridden intentionally for testing but violate the RFC if used outside the scope of testing.
-
-
Method Details
-
maxHeaderTableSize
Description copied from interface:Http2HeadersDecoder.Configuration
Represents the value for SETTINGS_HEADER_TABLE_SIZE. This method should only be called by Netty (not users) as a result of a receiving aSETTINGS
frame.- Specified by:
maxHeaderTableSize
in interfaceHttp2HeadersDecoder.Configuration
- Throws:
Http2Exception
-
maxHeaderTableSize
public long maxHeaderTableSize()Description copied from interface:Http2HeadersDecoder.Configuration
Represents the value for SETTINGS_HEADER_TABLE_SIZE. The initial value returned by this method must beHttp2CodecUtil.DEFAULT_HEADER_TABLE_SIZE
.- Specified by:
maxHeaderTableSize
in interfaceHttp2HeadersDecoder.Configuration
-
maxHeaderListSize
Description copied from interface:Http2HeadersDecoder.Configuration
Configure the maximum allowed size in bytes of each set of headers.This method should only be called by Netty (not users) as a result of a receiving a
SETTINGS
frame.- Specified by:
maxHeaderListSize
in interfaceHttp2HeadersDecoder.Configuration
- Parameters:
max
- SETTINGS_MAX_HEADER_LIST_SIZE. If this limit is exceeded the implementation should attempt to keep the HPACK header tables up to date by processing data from the peer, but aRST_STREAM
frame will be sent for the offending stream.goAwayMax
- Must be>= max
. AGO_AWAY
frame will be generated if this limit is exceeded for any particular stream.- Throws:
Http2Exception
- if limits exceed the RFC's boundaries ormax > goAwayMax
.
-
maxHeaderListSize
public long maxHeaderListSize()Description copied from interface:Http2HeadersDecoder.Configuration
Represents the value for SETTINGS_MAX_HEADER_LIST_SIZE.- Specified by:
maxHeaderListSize
in interfaceHttp2HeadersDecoder.Configuration
-
maxHeaderListSizeGoAway
public long maxHeaderListSizeGoAway()Description copied from interface:Http2HeadersDecoder.Configuration
Represents the upper bound in bytes for a set of headers before aGO_AWAY
should be sent. This will be<=
SETTINGS_MAX_HEADER_LIST_SIZE.- Specified by:
maxHeaderListSizeGoAway
in interfaceHttp2HeadersDecoder.Configuration
-
configuration
Description copied from interface:Http2HeadersDecoder
Get theHttp2HeadersDecoder.Configuration
for thisHttp2HeadersDecoder
- Specified by:
configuration
in interfaceHttp2HeadersDecoder
-
decodeHeaders
Description copied from interface:Http2HeadersDecoder
Decodes the given headers block and returns the headers.- Specified by:
decodeHeaders
in interfaceHttp2HeadersDecoder
- Throws:
Http2Exception
-
numberOfHeadersGuess
protected final int numberOfHeadersGuess()A weighted moving average estimating how many headers are expected during the decode process.- Returns:
- an estimate of how many headers are expected during the decode process.
-
validateHeaders
protected final boolean validateHeaders()Determines if the headers should be validated as a result of the decode operation.Note: This does not include validation of header values, since that is potentially expensive to do. Value validation is instead enabled separately.
- Returns:
true
if the headers should be validated as a result of the decode operation.
-
validateHeaderValues
protected boolean validateHeaderValues()Determines if the header values should be validated as a result of the decode operation.Note: This only validates the values of headers. All other header validations are instead enabled separately.
- Returns:
true
if the header values should be validated as a result of the decode operation.
-
newHeaders
Create a newHttp2Headers
object which will store the results of the decode operation.- Returns:
- a new
Http2Headers
object which will store the results of the decode operation.
-