Top Description Inners Fields Constructors Methods
org.apache.coyote.http2

public Class HpackDecoder

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.res.StringManager

A decoder for HPACK.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
HpackDecoder.HeaderEmitter

Interface implemented by the intended recipient of the headers.

Field Summary

Modifier and TypeField and Description
private volatile boolean
private int
currentMemorySize

the current calculates memory size, as per the HPACK algorithm

private static final int
private int
filledTableSlots

The current table size by index (aka the number of index positions that are filled up)

private int
firstSlotPosition

The current HEAD position of the header table.

private volatile int
private HpackDecoder.HeaderEmitter
headerEmitter

The object that receives the headers that are emitted from this decoder

private volatile int
private Hpack.HeaderField[]
headerTable

The header table

private static final Log
private int
private int
private int
maxMemorySizeHard

The maximum allowed memory size set by the container.

private int
maxMemorySizeSoft

The maximum memory size currently in use.

private static final StringManager

Constructor Summary

AccessConstructor and Description
pack-priv
HpackDecoder(int maxMemorySize)

pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
private void
pack-priv void
decode(ByteBuffer
The buffer
buffer
)

Decodes the provided frame data.

private void
emitHeader(String name, String value)

pack-priv int
pack-priv int
pack-priv int
pack-priv HpackDecoder.HeaderEmitter
pack-priv Hpack.HeaderField[]
pack-priv int
pack-priv int

Returns:

the real index into the array
getRealIndex
(int
The index from the hpack
index
)

because we use a ring buffer type construct, and don't actually shuffle items in the array, we need to figure out the real index to use.

private void
handleIndex(int
The index
index
)

Handle an indexed header representation

private String
private boolean
handleMaxMemorySizeChange(ByteBuffer buffer, int originalPos)

pack-priv boolean
pack-priv boolean
isHeaderSizeExceeded(int unreadSize)

pack-priv boolean
private String
readHeaderName(ByteBuffer buffer, int prefixLength)

private String
private String
readHuffmanString(int length, ByteBuffer buffer)

private void
pack-priv void
pack-priv void
setMaxHeaderCount(int maxHeaderCount)

pack-priv void
setMaxHeaderSize(int maxHeaderSize)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countedCookieback to summary
private volatile boolean countedCookie
currentMemorySizeback to summary
private int currentMemorySize

the current calculates memory size, as per the HPACK algorithm

DEFAULT_RING_BUFFER_SIZEback to summary
private static final int DEFAULT_RING_BUFFER_SIZE
filledTableSlotsback to summary
private int filledTableSlots

The current table size by index (aka the number of index positions that are filled up)

firstSlotPositionback to summary
private int firstSlotPosition

The current HEAD position of the header table. We use a ring buffer type construct as it would be silly to actually shuffle the items around in the array.

headerCountback to summary
private volatile int headerCount
headerEmitterback to summary
private HpackDecoder.HeaderEmitter headerEmitter

The object that receives the headers that are emitted from this decoder

headerSizeback to summary
private volatile int headerSize
headerTableback to summary
private Hpack.HeaderField[] headerTable

The header table

logback to summary
private static final Log log
maxHeaderCountback to summary
private int maxHeaderCount
maxHeaderSizeback to summary
private int maxHeaderSize
maxMemorySizeHardback to summary
private int maxMemorySizeHard

The maximum allowed memory size set by the container.

maxMemorySizeSoftback to summary
private int maxMemorySizeSoft

The maximum memory size currently in use. May be less than the hard limit.

smback to summary
private static final StringManager sm

Constructor Detail

HpackDecoderback to summary
pack-priv HpackDecoder(int maxMemorySize)
HpackDecoderback to summary
pack-priv HpackDecoder()

Method Detail

addEntryToHeaderTableback to summary
private void addEntryToHeaderTable(Hpack.HeaderField entry)
addStaticTableEntryback to summary
private void addStaticTableEntry(int index) throws HpackException
decodeback to summary
pack-priv void decode(ByteBuffer buffer) throws HpackException

Decodes the provided frame data. If this method leaves data in the buffer then this buffer should be compacted so this data is preserved, unless there is no more data in which case this should be considered a protocol error.

Parameters
buffer:ByteBuffer

The buffer

Exceptions
HpackException:
If the packed data is not valid
emitHeaderback to summary
private void emitHeader(String name, String value) throws HpackException
getCurrentMemorySizeback to summary
pack-priv int getCurrentMemorySize()
getFilledTableSlotsback to summary
pack-priv int getFilledTableSlots()
getFirstSlotPositionback to summary
pack-priv int getFirstSlotPosition()
getHeaderEmitterback to summary
pack-priv HpackDecoder.HeaderEmitter getHeaderEmitter()
getHeaderTableback to summary
pack-priv Hpack.HeaderField[] getHeaderTable()
getMaxMemorySizeSoftback to summary
pack-priv int getMaxMemorySizeSoft()
getRealIndexback to summary
pack-priv int getRealIndex(int index) throws HpackException

because we use a ring buffer type construct, and don't actually shuffle items in the array, we need to figure out the real index to use.

package private for unit tests

Parameters
index:int

The index from the hpack

Returns:int

the real index into the array

handleIndexback to summary
private void handleIndex(int index) throws HpackException

Handle an indexed header representation

Parameters
index:int

The index

Exceptions
HpackException:
If an error occurs processing the given index
handleIndexedHeaderNameback to summary
private String handleIndexedHeaderName(int index) throws HpackException
handleMaxMemorySizeChangeback to summary
private boolean handleMaxMemorySizeChange(ByteBuffer buffer, int originalPos) throws HpackException
isHeaderCountExceededback to summary
pack-priv boolean isHeaderCountExceeded()
isHeaderSizeExceededback to summary
pack-priv boolean isHeaderSizeExceeded(int unreadSize)
isHeaderSwallowSizeExceededback to summary
pack-priv boolean isHeaderSwallowSizeExceeded(int unreadSize)
readHeaderNameback to summary
private String readHeaderName(ByteBuffer buffer, int prefixLength) throws HpackException
readHpackStringback to summary
private String readHpackString(ByteBuffer buffer) throws HpackException
readHuffmanStringback to summary
private String readHuffmanString(int length, ByteBuffer buffer) throws HpackException
resizeIfRequiredback to summary
private void resizeIfRequired()
setHeaderEmitterback to summary
pack-priv void setHeaderEmitter(HpackDecoder.HeaderEmitter headerEmitter)
setMaxHeaderCountback to summary
pack-priv void setMaxHeaderCount(int maxHeaderCount)
setMaxHeaderSizeback to summary
pack-priv void setMaxHeaderSize(int maxHeaderSize)
org.apache.coyote.http2 back to summary

pack-priv Interface HpackDecoder.HeaderEmitter

Known Direct Implementers
org.apache.coyote.http2.Stream, org.apache.coyote.http2.HeaderSink

Interface implemented by the intended recipient of the headers.

Method Summary

Modifier and TypeMethod and Description
public void
emitHeader(String
Header name
name
,
String
Header value
value
)

Pass a single header to the recipient.

public void
setHeaderException(StreamException
The exception to use when resetting the stream
streamException
)

Inform the recipient of the headers that a stream error needs to be triggered using the given message when validateHeaders() is called.

public void
validateHeaders()

Are the headers pass to the recipient so far valid?

Method Detail

emitHeaderback to summary
public void emitHeader(String name, String value) throws HpackException

Pass a single header to the recipient.

Parameters
name:String

Header name

value:String

Header value

Exceptions
HpackException:
If a header is received that is not compliant with the HTTP/2 specification
setHeaderExceptionback to summary
public void setHeaderException(StreamException streamException)

Inform the recipient of the headers that a stream error needs to be triggered using the given message when validateHeaders() is called. This is used when the Parser becomes aware of an error that is not visible to the recipient.

Parameters
streamException:StreamException

The exception to use when resetting the stream

validateHeadersback to summary
public void validateHeaders() throws StreamException

Are the headers pass to the recipient so far valid? The decoder needs to process all the headers to maintain state even if there is a problem. In addition, it is easy for the the intended recipient to track if the complete set of headers is valid since to do that state needs to be maintained between the parsing of the initial headers and the parsing of any trailer headers. The recipient is the best place to maintain that state.

Exceptions
StreamException:
If the headers received to date are not valid