Top Description Inners Fields Constructors Methods
io.netty.handler.codec.http2

pack-priv final Class HpackEncoder

extends Object
Class Inheritance
Imports
io.netty.buffer.ByteBuf, io.netty.handler.codec.http2.HpackUtil.IndexType, .Http2HeadersEncoder.SensitivityDetector, io.netty.util.AsciiString, .CharsetUtil, java.util.Map

An HPACK encoder.

Implementation Note

This class is security sensitive, and depends on users correctly identifying their headers as security sensitive or not. If a header is considered not sensitive, methods names "insensitive" are used which are fast, but don't provide any security guarantees.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final byte
private final HpackEncoder.NameValueEntry
private final HpackHuffmanEncoder
pack-priv static final int
private final int
private final boolean
private HpackEncoder.NameValueEntry
private long
private long
private final HpackEncoder.NameEntry[]
private final HpackEncoder.NameValueEntry[]
pack-priv static final int
private long

Constructor Summary

AccessConstructor and Description
pack-priv
HpackEncoder()

Creates a new encoder.

pack-priv
HpackEncoder(boolean ignoreMaxHeaderListSize)

Creates a new encoder.

pack-priv
HpackEncoder(boolean ignoreMaxHeaderListSize, int arraySizeHint, int huffCodeThreshold)

Creates a new encoder.

Method Summary

Modifier and TypeMethod and Description
private void
addNameEntry(CharSequence name, int nameHash, int nextCounter)

private void
addNameValueEntry(CharSequence name, CharSequence value, int nameHash, int valueHash, int nextCounter)

private int
bucket(int h)

Returns the bucket of the hash table for the hash code h.

private void
encodeAndAddEntries(ByteBuf out, CharSequence name, int nameHash, CharSequence value, int valueHash)

private void
encodeHeader(ByteBuf out, CharSequence name, CharSequence value, boolean sensitive, long headerSize)

Encode the header field into the header block.

public void
encodeHeaders(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector)

Encode the header field into the header block.

private void
private void
private static void
encodeInteger(ByteBuf out, int mask, int n, int i)

Encode integer according to Section 5.1.

private static void
encodeInteger(ByteBuf out, int mask, int n, long i)

Encode integer according to Section 5.1.

private void
encodeLiteral(ByteBuf out, CharSequence name, CharSequence value, HpackUtil.IndexType indexType, int nameIndex)

Encode literal header field according to Section 6.2.

private void
encodeStringLiteral(ByteBuf out, CharSequence string)

Encode string literal according to Section 5.2.

private void
ensureCapacity(long headerSize)

Ensure that the dynamic table has enough room to hold 'headerSize' more bytes.

private HpackEncoder.NameEntry
getEntry(CharSequence name, int nameHash)

Returns the lowest index value for the header field name in the dynamic table.

private HpackEncoder.NameValueEntry
getEntryInsensitive(CharSequence name, int nameHash, CharSequence value, int valueHash)

Returns the header entry with the lowest index value for the header field.

pack-priv HpackHeaderField
getHeaderField(int index)

Return the header field at the given index.

private int
getIndex(int counter)

Compute the index into the dynamic table given the counter in the header entry.

private int
getIndexPlusOffset(int counter)

public long
public long
getMaxHeaderTableSize()

Return the maximum table size.

private int
private static int
hash(int nameHash, int valueHash)

private boolean
private int
pack-priv int
length()

Return the number of header fields in the dynamic table.

private void
remove()

Remove the oldest header field from the dynamic table.

private void
private void
public void
setMaxHeaderListSize(long maxHeaderListSize)

public void
setMaxHeaderTableSize(ByteBuf out, long maxHeaderTableSize)

Set the maximum table size.

pack-priv long
size()

Return the size of the dynamic table.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hashMaskback to summary
private final byte hashMask
hpackHuffmanEncoderback to summary
private final HpackHuffmanEncoder hpackHuffmanEncoder
HUFF_CODE_THRESHOLDback to summary
pack-priv static final int HUFF_CODE_THRESHOLD
huffCodeThresholdback to summary
private final int huffCodeThreshold
ignoreMaxHeaderListSizeback to summary
private final boolean ignoreMaxHeaderListSize
latestback to summary
private HpackEncoder.NameValueEntry latest
maxHeaderListSizeback to summary
private long maxHeaderListSize
maxHeaderTableSizeback to summary
private long maxHeaderTableSize
nameEntriesback to summary
private final HpackEncoder.NameEntry[] nameEntries
nameValueEntriesback to summary
private final HpackEncoder.NameValueEntry[] nameValueEntries
NOT_FOUNDback to summary
pack-priv static final int NOT_FOUND
sizeback to summary
private long size

Constructor Detail

HpackEncoderback to summary
pack-priv HpackEncoder()

Creates a new encoder.

HpackEncoderback to summary
pack-priv HpackEncoder(boolean ignoreMaxHeaderListSize)

Creates a new encoder.

HpackEncoderback to summary
pack-priv HpackEncoder(boolean ignoreMaxHeaderListSize, int arraySizeHint, int huffCodeThreshold)

Creates a new encoder.

Method Detail

addNameEntryback to summary
private void addNameEntry(CharSequence name, int nameHash, int nextCounter)
addNameValueEntryback to summary
private void addNameValueEntry(CharSequence name, CharSequence value, int nameHash, int valueHash, int nextCounter)
bucketback to summary
private int bucket(int h)

Returns the bucket of the hash table for the hash code h.

encodeAndAddEntriesback to summary
private void encodeAndAddEntries(ByteBuf out, CharSequence name, int nameHash, CharSequence value, int valueHash)
encodeHeaderback to summary
private void encodeHeader(ByteBuf out, CharSequence name, CharSequence value, boolean sensitive, long headerSize)

Encode the header field into the header block.

The given CharSequences must be immutable!

encodeHeadersback to summary
public void encodeHeaders(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2Exception

Encode the header field into the header block.

The given CharSequences must be immutable!

encodeHeadersEnforceMaxHeaderListSizeback to summary
private void encodeHeadersEnforceMaxHeaderListSize(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2Exception
encodeHeadersIgnoreMaxHeaderListSizeback to summary
private void encodeHeadersIgnoreMaxHeaderListSize(ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector)
encodeIntegerback to summary
private static void encodeInteger(ByteBuf out, int mask, int n, int i)

Encode integer according to Section 5.1.

encodeIntegerback to summary
private static void encodeInteger(ByteBuf out, int mask, int n, long i)

Encode integer according to Section 5.1.

encodeLiteralback to summary
private void encodeLiteral(ByteBuf out, CharSequence name, CharSequence value, HpackUtil.IndexType indexType, int nameIndex)

Encode literal header field according to Section 6.2.

encodeStringLiteralback to summary
private void encodeStringLiteral(ByteBuf out, CharSequence string)

Encode string literal according to Section 5.2.

ensureCapacityback to summary
private void ensureCapacity(long headerSize)

Ensure that the dynamic table has enough room to hold 'headerSize' more bytes. Removes the oldest entry from the dynamic table until sufficient space is available.

getEntryback to summary
private HpackEncoder.NameEntry getEntry(CharSequence name, int nameHash)

Returns the lowest index value for the header field name in the dynamic table. Returns -1 if the header field name is not in the dynamic table.

getEntryInsensitiveback to summary
private HpackEncoder.NameValueEntry getEntryInsensitive(CharSequence name, int nameHash, CharSequence value, int valueHash)

Returns the header entry with the lowest index value for the header field. Returns null if header field is not in the dynamic table.

getHeaderFieldback to summary
pack-priv HpackHeaderField getHeaderField(int index)

Return the header field at the given index. Exposed for testing.

getIndexback to summary
private int getIndex(int counter)

Compute the index into the dynamic table given the counter in the header entry.

getIndexPlusOffsetback to summary
private int getIndexPlusOffset(int counter)
getMaxHeaderListSizeback to summary
public long getMaxHeaderListSize()
getMaxHeaderTableSizeback to summary
public long getMaxHeaderTableSize()

Return the maximum table size.

getNameIndexback to summary
private int getNameIndex(CharSequence name)
hashback to summary
private static int hash(int nameHash, int valueHash)
isEmptyback to summary
private boolean isEmpty()
latestCounterback to summary
private int latestCounter()
lengthback to summary
pack-priv int length()

Return the number of header fields in the dynamic table. Exposed for testing.

removeback to summary
private void remove()

Remove the oldest header field from the dynamic table.

removeNameEntryMatchingCounterback to summary
private void removeNameEntryMatchingCounter(CharSequence name, int counter)
removeNameValueEntryback to summary
private void removeNameValueEntry(HpackEncoder.NameValueEntry eldest)
setMaxHeaderListSizeback to summary
public void setMaxHeaderListSize(long maxHeaderListSize) throws Http2Exception
setMaxHeaderTableSizeback to summary
public void setMaxHeaderTableSize(ByteBuf out, long maxHeaderTableSize) throws Http2Exception

Set the maximum table size.

sizeback to summary
pack-priv long size()

Return the size of the dynamic table. Exposed for testing.

io.netty.handler.codec.http2 back to summary

private final Class HpackEncoder.NameEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv final int
pack-priv final CharSequence
pack-priv HpackEncoder.NameEntry

Constructor Summary

AccessConstructor and Description
pack-priv
NameEntry(int hash, CharSequence name, int counter, HpackEncoder.NameEntry next)

Method Summary

Modifier and TypeMethod and Description
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

counterback to summary
pack-priv int counter
hashback to summary
pack-priv final int hash
nameback to summary
pack-priv final CharSequence name
nextback to summary
pack-priv HpackEncoder.NameEntry next

Constructor Detail

NameEntryback to summary
pack-priv NameEntry(int hash, CharSequence name, int counter, HpackEncoder.NameEntry next)

Method Detail

io.netty.handler.codec.http2 back to summary

private final Class HpackEncoder.NameValueEntry

extends HpackHeaderField
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv HpackEncoder.NameValueEntry
pack-priv final int
pack-priv final int
pack-priv HpackEncoder.NameValueEntry
Inherited from io.netty.handler.codec.http2.HpackHeaderField:
HEADER_ENTRY_OVERHEADnamevalue

Constructor Summary

AccessConstructor and Description
pack-priv
NameValueEntry(int hash, CharSequence name, CharSequence value, int counter, HpackEncoder.NameValueEntry next)

Method Summary

Modifier and TypeMethod and Description
Inherited from io.netty.handler.codec.http2.HpackHeaderField:
equalsForTestsizesizeOftoString

Field Detail

afterback to summary
pack-priv HpackEncoder.NameValueEntry after
counterback to summary
pack-priv final int counter
hashback to summary
pack-priv final int hash
nextback to summary
pack-priv HpackEncoder.NameValueEntry next

Constructor Detail

NameValueEntryback to summary
pack-priv NameValueEntry(int hash, CharSequence name, CharSequence value, int counter, HpackEncoder.NameValueEntry next)

Method Detail