1
- hpack: HTTP/2 Header Compression for Python
2
- ===========================================
1
+ hpack: Pure-Python HTTP/2 Header Encoding
2
+ =========================================
3
3
4
4
hpack provides a simple Python interface to the `HPACK `_ compression algorithm,
5
- used to compress HTTP headers in HTTP/2. Used by some of the most popular
6
- HTTP/2 implementations in Python, HPACK offers a great Python interface as well
7
- as optional upgrade to optimised C-based compression routines from ` nghttp2 `_ .
5
+ used to encode HTTP headers in HTTP/2. Used by some of the most popular
6
+ HTTP/2 implementations in Python, the hpack library offers a great and simple
7
+ Python interface without any dependencies, strictly confirming to ` RFC 7541 `_. .
8
8
9
9
Using hpack is easy:
10
10
11
11
.. code-block :: python
12
12
13
13
from hpack import Encoder, Decoder
14
14
15
+ headers = [
16
+ (' :method' , ' GET' ),
17
+ (' :path' , ' /jimiscool/' ),
18
+ (' X-Some-Header' , ' some_value' ),
19
+ ]
20
+
15
21
e = Encoder()
16
22
encoded_bytes = e.encode(headers)
17
23
18
24
d = Decoder()
19
25
decoded_headers = d.decode(encoded_bytes)
20
26
21
- hpack will transparently use nghttp2 on CPython if it's available, gaining even
22
- better compression efficiency and speed, but it also makes available a
23
- pure-Python implementation that conforms strictly to `RFC 7541 `_.
24
27
25
28
Contents
26
29
--------
@@ -34,5 +37,4 @@ Contents
34
37
35
38
36
39
.. _HPACK : https://tools.ietf.org/html/rfc7541
37
- .. _nghttp2 : https://nghttp2.org/
38
40
.. _RFC 7541 : https://tools.ietf.org/html/rfc7541
0 commit comments