Pure-Python HPACK header compression
This module contains a pure-Python HTTP/2 header encoding (HPACK) logic for use in Python programs that implement HTTP/2. It also contains a compatibility layer that automatically enables the use of nghttp2 if it’s available.
hpack welcomes contributions from anyone! Unlike many other projects we are happy to accept cosmetic contributions and small contributions, in addition to large feature requests and changes.
Before you contribute (either by opening an issue or filing a pull request), please read the contribution guidelines.
hpack is made available under the MIT License. For more details, see the LICENSE file in the repository.
CVE-2016-6581: HPACK Bomb. This release now enforces a maximum value of the decompressed size of the header list. This is to avoid the so-called “HPACK Bomb” vulnerability, which is caused when a malicious peer sends a compressed HPACK body that decompresses to a gigantic header list size.
This also adds a OversizedHeaderListError, which is thrown by the decode method if the maximum header list size is being violated. This places the HPACK decoder into a broken state: it must not be used after this exception is thrown.
This also adds a max_header_list_size to the Decoder object. This controls the maximum allowable decompressed size of the header list. By default this is set to 64kB.
API Changes (Backward Compatible)
- Added HeaderTuple and NeverIndexedHeaderTuple classes that signal whether a given header field may ever be indexed in HTTP/2 header compression.
- Changed Decoder.decode() to return the newly added HeaderTuple class and subclass. These objects behave like two-tuples, so this change does not break working code.
- Improve Huffman decoding speed by 4x using an approach borrowed from nghttp2.
- Improve HPACK decoding speed by 10% by caching header table sizes.
- When passing a dictionary or dictionary subclass to Encoder.encode, HPACK now ensures that HTTP/2 special headers (headers whose names begin with : characters) appear first in the header block.
API Changes (Backward Compatible)
- Added new InvalidTableIndex exception, a subclass of HPACKDecodingError.
- Instead of throwing IndexError when encountering invalid encoded integers HPACK now throws HPACKDecodingError.
- Instead of throwing UnicodeDecodeError when encountering headers that are not UTF-8 encoded, HPACK now throws HPACKDecodingError.
- Instead of throwing IndexError when encountering invalid table offsets, HPACK now throws InvalidTableIndex.
- Added raw flag to decode, allowing decode to return bytes instead of attempting to decode the headers as UTF-8.
- memoryview objects are now used when decoding HPACK, improving the performance by avoiding unnecessary data copies.
- Fixed a bug where the Python HPACK implementation would only emit header table size changes for the total change between one header block and another, rather than for the entire sequence of changes.
- Remove unused HPACKEncodingError.
- Add the shortcut ability to import the public API (Encoder, Decoder, HPACKError, HPACKDecodingError) directly, rather than from hpack.hpack.
- Add support for emitting ‘never indexed’ header fields, by using an optional third element in the header tuple. With thanks to @jimcarreer!
- Header fields that have names matching header table entries are now added to the header table. This improves compression efficiency at the cost of slightly more table operations. With thanks to Tatsuhiro Tsujikawa.
- Initial fork of the code from hyper.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|hpack-2.3.0-py2.py3-none-any.whl (37.0 kB) Copy SHA256 hash SHA256||Wheel||py2.py3||Aug 4, 2016|
|hpack-2.3.0.tar.gz (41.6 kB) Copy SHA256 hash SHA256||Source||None||Aug 4, 2016|