Package io.netty.handler.codec.http2
Class HpackEncoder
java.lang.Object
io.netty.handler.codec.http2.HpackEncoder
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 Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte
private final HpackEncoder.NameValueEntry
private final HpackHuffmanEncoder
(package private) static final int
private final int
private final boolean
private HpackEncoder.NameValueEntry
private long
private long
private final HpackEncoder.NameEntry[]
private final HpackEncoder.NameValueEntry[]
(package private) static final int
private long
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new encoder.HpackEncoder
(boolean ignoreMaxHeaderListSize) Creates a new encoder.HpackEncoder
(boolean ignoreMaxHeaderListSize, int arraySizeHint, int huffCodeThreshold) Creates a new encoder. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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.void
encodeHeaders
(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) Encode the header field into the header block.private void
encodeHeadersEnforceMaxHeaderListSize
(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) private void
encodeHeadersIgnoreMaxHeaderListSize
(ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) 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.(package private) 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) long
long
Return the maximum table size.private int
getNameIndex
(CharSequence name) private static int
hash
(int nameHash, int valueHash) private boolean
isEmpty()
private int
(package private) 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
removeNameEntryMatchingCounter
(CharSequence name, int counter) private void
void
setMaxHeaderListSize
(long maxHeaderListSize) void
setMaxHeaderTableSize
(ByteBuf out, long maxHeaderTableSize) Set the maximum table size.(package private) long
size()
Return the size of the dynamic table.
-
Field Details
-
NOT_FOUND
static final int NOT_FOUND- See Also:
-
HUFF_CODE_THRESHOLD
static final int HUFF_CODE_THRESHOLD- See Also:
-
nameEntries
-
nameValueEntries
-
head
-
latest
-
hpackHuffmanEncoder
-
hashMask
private final byte hashMask -
ignoreMaxHeaderListSize
private final boolean ignoreMaxHeaderListSize -
huffCodeThreshold
private final int huffCodeThreshold -
size
private long size -
maxHeaderTableSize
private long maxHeaderTableSize -
maxHeaderListSize
private long maxHeaderListSize
-
-
Constructor Details
-
HpackEncoder
HpackEncoder()Creates a new encoder. -
HpackEncoder
HpackEncoder(boolean ignoreMaxHeaderListSize) Creates a new encoder. -
HpackEncoder
HpackEncoder(boolean ignoreMaxHeaderListSize, int arraySizeHint, int huffCodeThreshold) Creates a new encoder.
-
-
Method Details
-
encodeHeaders
public void encodeHeaders(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2Exception Encode the header field into the header block.The given
CharSequence
s must be immutable!- Throws:
Http2Exception
-
encodeHeadersEnforceMaxHeaderListSize
private void encodeHeadersEnforceMaxHeaderListSize(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2Exception - Throws:
Http2Exception
-
encodeHeadersIgnoreMaxHeaderListSize
private void encodeHeadersIgnoreMaxHeaderListSize(ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) -
encodeHeader
private void encodeHeader(ByteBuf out, CharSequence name, CharSequence value, boolean sensitive, long headerSize) Encode the header field into the header block.The given
CharSequence
s must be immutable! -
encodeAndAddEntries
private void encodeAndAddEntries(ByteBuf out, CharSequence name, int nameHash, CharSequence value, int valueHash) -
setMaxHeaderTableSize
Set the maximum table size.- Throws:
Http2Exception
-
getMaxHeaderTableSize
public long getMaxHeaderTableSize()Return the maximum table size. -
setMaxHeaderListSize
- Throws:
Http2Exception
-
getMaxHeaderListSize
public long getMaxHeaderListSize() -
encodeInteger
Encode integer according to Section 5.1. -
encodeInteger
Encode integer according to Section 5.1. -
encodeStringLiteral
Encode string literal according to Section 5.2. -
encodeLiteral
private void encodeLiteral(ByteBuf out, CharSequence name, CharSequence value, HpackUtil.IndexType indexType, int nameIndex) Encode literal header field according to Section 6.2. -
getNameIndex
-
ensureCapacity
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. -
length
int length()Return the number of header fields in the dynamic table. Exposed for testing. -
size
long size()Return the size of the dynamic table. Exposed for testing. -
getHeaderField
Return the header field at the given index. Exposed for testing. -
getEntryInsensitive
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. -
getEntry
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. -
getIndexPlusOffset
private int getIndexPlusOffset(int counter) -
getIndex
private int getIndex(int counter) Compute the index into the dynamic table given the counter in the header entry. -
latestCounter
private int latestCounter() -
addNameEntry
-
addNameValueEntry
private void addNameValueEntry(CharSequence name, CharSequence value, int nameHash, int valueHash, int nextCounter) -
remove
private void remove()Remove the oldest header field from the dynamic table. -
isEmpty
private boolean isEmpty() -
removeNameValueEntry
-
removeNameEntryMatchingCounter
-
bucket
private int bucket(int h) Returns the bucket of the hash table for the hash code h. -
hash
private static int hash(int nameHash, int valueHash)
-