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

pack-priv final Class HpackEncoder

extends Object
Class Inheritance
Imports
io.netty5.buffer.Buffer, io.netty5.handler.codec.http2.HpackUtil.IndexType, .Http2HeadersEncoder.SensitivityDetector, io.netty5.handler.codec.http2.headers.Http2Headers, io.netty5.util.AsciiString, java.nio.charset.StandardCharsets, java.util.Arrays, .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
HpackEncoder.HeaderEntry

A linked hash map HpackHeaderField entry.

Field Summary

Modifier and TypeField and Description
private final byte
private final HpackEncoder.HeaderEntry
private final HpackEncoder.HeaderEntry[]
private final HpackHuffmanEncoder
pack-priv static final int
private final int
private final boolean
private long
private long
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
add(CharSequence name, CharSequence value, long headerSize)

Add the header field to the dynamic table.

private void
clear()

Remove all entries from the dynamic table.

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

Encode the header field into the header block.

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

Encode the header field into the header block.

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

Encode integer according to Section 5.1.

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

Encode integer according to Section 5.1.

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

Encode literal header field according to Section 6.2.

private void
encodeStringLiteral(Buffer 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.HeaderEntry
getEntryInsensitive(CharSequence name, CharSequence value)

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(CharSequence name)

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

private int
getIndex(int index)

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

public long
public long
getMaxHeaderTableSize()

Return the maximum table size.

private int
private int
index(int h)

Returns the index into the hash table for the hash code h.

pack-priv int
length()

Return the number of header fields in the dynamic table.

private HpackHeaderField
remove()

Remove and return the oldest header field from the dynamic table.

public void
setMaxHeaderListSize(long maxHeaderListSize)

public void
setMaxHeaderTableSize(Buffer 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
headerFieldsback to summary
private final HpackEncoder.HeaderEntry[] headerFields
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
maxHeaderListSizeback to summary
private long maxHeaderListSize
maxHeaderTableSizeback to summary
private long maxHeaderTableSize
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

addback to summary
private void add(CharSequence name, CharSequence value, long headerSize)

Add the header field to the dynamic table. Entries are evicted from the dynamic table until the size of the table and the new header field is less than the table's maxHeaderTableSize. If the size of the new entry is larger than the table's maxHeaderTableSize, the dynamic table will be cleared.

clearback to summary
private void clear()

Remove all entries from the dynamic table.

encodeHeaderback to summary
private void encodeHeader(Buffer 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, Buffer 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, Buffer out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2Exception
encodeHeadersIgnoreMaxHeaderListSizeback to summary
private void encodeHeadersIgnoreMaxHeaderListSize(Buffer out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2Exception
encodeIntegerback to summary
private static void encodeInteger(Buffer out, int mask, int n, int i)

Encode integer according to Section 5.1.

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

Encode integer according to Section 5.1.

encodeLiteralback to summary
private void encodeLiteral(Buffer 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(Buffer 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.

getEntryInsensitiveback to summary
private HpackEncoder.HeaderEntry getEntryInsensitive(CharSequence name, CharSequence value)

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(CharSequence name)

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.

getIndexback to summary
private int getIndex(int index)

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

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)
indexback to summary
private int index(int h)

Returns the index into the hash table for the hash code h.

lengthback to summary
pack-priv int length()

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

removeback to summary
private HpackHeaderField remove()

Remove and return the oldest header field from the dynamic table.

setMaxHeaderListSizeback to summary
public void setMaxHeaderListSize(long maxHeaderListSize) throws Http2Exception
setMaxHeaderTableSizeback to summary
public void setMaxHeaderTableSize(Buffer 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.netty5.handler.codec.http2 back to summary

private final Class HpackEncoder.HeaderEntry

extends HpackHeaderField
Class Inheritance

A linked hash map HpackHeaderField entry.

Field Summary

Modifier and TypeField and Description
pack-priv HpackEncoder.HeaderEntry
pack-priv HpackEncoder.HeaderEntry
pack-priv int
pack-priv int
pack-priv HpackEncoder.HeaderEntry
Inherited from io.netty5.handler.codec.http2.HpackHeaderField:
HEADER_ENTRY_OVERHEADnamevalue

Constructor Summary

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

Creates new entry.

Method Summary

Modifier and TypeMethod and Description
private void
addBefore(HpackEncoder.HeaderEntry existingEntry)

Inserts this entry before the specified existing entry in the list.

private void
remove()

Removes this entry from the linked list.

Inherited from io.netty5.handler.codec.http2.HpackHeaderField:
equalsForTestsizesizeOftoString

Field Detail

afterback to summary
pack-priv HpackEncoder.HeaderEntry after
beforeback to summary
pack-priv HpackEncoder.HeaderEntry before
hashback to summary
pack-priv int hash
indexback to summary
pack-priv int index
nextback to summary
pack-priv HpackEncoder.HeaderEntry next

Constructor Detail

HeaderEntryback to summary
pack-priv HeaderEntry(int hash, CharSequence name, CharSequence value, int index, HpackEncoder.HeaderEntry next)

Creates new entry.

Method Detail

addBeforeback to summary
private void addBefore(HpackEncoder.HeaderEntry existingEntry)

Inserts this entry before the specified existing entry in the list.

removeback to summary
private void remove()

Removes this entry from the linked list.