Package io.netty.handler.codec.http2
Class HpackEncoder
- java.lang.Object
-
- io.netty.handler.codec.http2.HpackEncoder
-
final class HpackEncoder extends java.lang.ObjectAn 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 Classes Modifier and Type Class Description private static classHpackEncoder.HeaderEntryA linked hash map HpackHeaderField entry.
-
Field Summary
Fields Modifier and Type Field Description private bytehashMaskprivate HpackEncoder.HeaderEntryheadprivate HpackEncoder.HeaderEntry[]headerFieldsprivate HpackHuffmanEncoderhpackHuffmanEncoder(package private) static intHUFF_CODE_THRESHOLDprivate inthuffCodeThresholdprivate booleanignoreMaxHeaderListSizeprivate longmaxHeaderListSizeprivate longmaxHeaderTableSizeprivate longsize
-
Constructor Summary
Constructors Constructor Description HpackEncoder()Creates a new encoder.HpackEncoder(boolean ignoreMaxHeaderListSize)Creates a new encoder.HpackEncoder(boolean ignoreMaxHeaderListSize, int arraySizeHint, int huffCodeThreshold)Creates a new encoder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadd(java.lang.CharSequence name, java.lang.CharSequence value, long headerSize)Add the header field to the dynamic table.private voidclear()Remove all entries from the dynamic table.private voidencodeHeader(ByteBuf out, java.lang.CharSequence name, java.lang.CharSequence value, boolean sensitive, long headerSize)Encode the header field into the header block.voidencodeHeaders(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector)Encode the header field into the header block.private voidencodeHeadersEnforceMaxHeaderListSize(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector)private voidencodeHeadersIgnoreMaxHeaderListSize(ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector)private static voidencodeInteger(ByteBuf out, int mask, int n, int i)Encode integer according to Section 5.1.private static voidencodeInteger(ByteBuf out, int mask, int n, long i)Encode integer according to Section 5.1.private voidencodeLiteral(ByteBuf out, java.lang.CharSequence name, java.lang.CharSequence value, HpackUtil.IndexType indexType, int nameIndex)Encode literal header field according to Section 6.2.private voidencodeStringLiteral(ByteBuf out, java.lang.CharSequence string)Encode string literal according to Section 5.2.private voidensureCapacity(long headerSize)Ensure that the dynamic table has enough room to hold 'headerSize' more bytes.private HpackEncoder.HeaderEntrygetEntryInsensitive(java.lang.CharSequence name, java.lang.CharSequence value)Returns the header entry with the lowest index value for the header field.(package private) HpackHeaderFieldgetHeaderField(int index)Return the header field at the given index.private intgetIndex(int index)Compute the index into the dynamic table given the index in the header entry.private intgetIndex(java.lang.CharSequence name)Returns the lowest index value for the header field name in the dynamic table.longgetMaxHeaderListSize()longgetMaxHeaderTableSize()Return the maximum table size.private intgetNameIndex(java.lang.CharSequence name)private intindex(int h)Returns the index into the hash table for the hash code h.(package private) intlength()Return the number of header fields in the dynamic table.private HpackHeaderFieldremove()Remove and return the oldest header field from the dynamic table.voidsetMaxHeaderListSize(long maxHeaderListSize)voidsetMaxHeaderTableSize(ByteBuf out, long maxHeaderTableSize)Set the maximum table size.(package private) longsize()Return the size of the dynamic table.
-
-
-
Field Detail
-
HUFF_CODE_THRESHOLD
static final int HUFF_CODE_THRESHOLD
- See Also:
- Constant Field Values
-
headerFields
private final HpackEncoder.HeaderEntry[] headerFields
-
head
private final HpackEncoder.HeaderEntry head
-
hpackHuffmanEncoder
private final HpackHuffmanEncoder 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
-
-
Method Detail
-
encodeHeaders
public void encodeHeaders(int streamId, ByteBuf out, Http2Headers headers, Http2HeadersEncoder.SensitivityDetector sensitivityDetector) throws Http2ExceptionEncode the header field into the header block. The givenCharSequences 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) throws Http2Exception
- Throws:
Http2Exception
-
encodeHeader
private void encodeHeader(ByteBuf out, java.lang.CharSequence name, java.lang.CharSequence value, boolean sensitive, long headerSize)
Encode the header field into the header block. The givenCharSequences must be immutable!
-
setMaxHeaderTableSize
public void setMaxHeaderTableSize(ByteBuf out, long maxHeaderTableSize) throws Http2Exception
Set the maximum table size.- Throws:
Http2Exception
-
getMaxHeaderTableSize
public long getMaxHeaderTableSize()
Return the maximum table size.
-
setMaxHeaderListSize
public void setMaxHeaderListSize(long maxHeaderListSize) throws Http2Exception- Throws:
Http2Exception
-
getMaxHeaderListSize
public long getMaxHeaderListSize()
-
encodeInteger
private static void encodeInteger(ByteBuf out, int mask, int n, int i)
Encode integer according to Section 5.1.
-
encodeInteger
private static void encodeInteger(ByteBuf out, int mask, int n, long i)
Encode integer according to Section 5.1.
-
encodeStringLiteral
private void encodeStringLiteral(ByteBuf out, java.lang.CharSequence string)
Encode string literal according to Section 5.2.
-
encodeLiteral
private void encodeLiteral(ByteBuf out, java.lang.CharSequence name, java.lang.CharSequence value, HpackUtil.IndexType indexType, int nameIndex)
Encode literal header field according to Section 6.2.
-
getNameIndex
private int getNameIndex(java.lang.CharSequence name)
-
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
HpackHeaderField getHeaderField(int index)
Return the header field at the given index. Exposed for testing.
-
getEntryInsensitive
private HpackEncoder.HeaderEntry getEntryInsensitive(java.lang.CharSequence name, java.lang.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.
-
getIndex
private int getIndex(java.lang.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.
-
getIndex
private int getIndex(int index)
Compute the index into the dynamic table given the index in the header entry.
-
add
private void add(java.lang.CharSequence name, java.lang.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.
-
remove
private HpackHeaderField remove()
Remove and return the oldest header field from the dynamic table.
-
clear
private void clear()
Remove all entries from the dynamic table.
-
index
private int index(int h)
Returns the index into the hash table for the hash code h.
-
-