hpack API¶
This document provides the HPACK API.
-
class
hpack.
Encoder
¶ An HPACK encoder object. This object takes HTTP headers and emits encoded HTTP/2 header blocks.
-
encode
(headers, huffman=True)¶ Takes a set of headers and encodes them into a HPACK-encoded header block.
Parameters: - headers –
The headers to encode. Must be either an iterable of tuples or a
dict
.If an iterable of tuples, the tuples may be either two-tuples or three-tuples. If they are two-tuples, the tuples must be of the format
(name, value)
. If they are three-tuples, they must be of the format(name, value, sensitive)
, wheresensitive
is a boolean value indicating whether the header should be added to header tables anywhere. If not present,sensitive
defaults toFalse
. - huffman – (optional) Whether to Huffman-encode any header sent as a literal value. Except for use when debugging, it is recommended that this be left enabled.
Returns: A bytestring containing the HPACK-encoded header block.
- headers –
-
header_table_size
¶ Controls the size of the HPACK header table.
-
-
class
hpack.
Decoder
¶ An HPACK decoder object.
-
decode
(data)¶ Takes an HPACK-encoded header block and decodes it into a header set.
Parameters: data – A bytestring representing a complete HPACK-encoded header block. Returns: A list of two-tuples of (name, value)
representing the HPACK-encoded headers, in the order they were decoded.Raises: HPACKDecodingError – If an error is encountered while decoding the header block.
-
header_table_size
¶ Controls the size of the HPACK header table.
-
-
class
hpack.
HPACKError
¶ The base class for all
hpack
exceptions.
-
class
hpack.
HPACKDecodingError
¶ An error has been encountered while performing HPACK decoding.