👻
【Python】pylsqpack でヘッダーを QPACK 形式に圧縮する
pip3 で pylsqpack をインストール
pip3 install pylsqpack
スクリプトを貼る
test.py
from pylsqpack import Encoder, Decoder
headers = [(b':method', b'GET'), (b':scheme', b'https'),
(b':path', b'/resource'), (b':authority', b'example.org')]
print(headers)
e = Encoder()
encoded = e.encode(0, headers)
print(encoded[1])
d = Decoder(1000, 1000)
ret = d.feed_header(20, encoded[1])
print(ret[1])
結果は次のとおり
[(b':method', b'GET'), (b':scheme', b'https'), (b':path', b'/resource'), (b':authority', b'example.org')]
b'\x00\x00\xd1\xd7Q\x87b\xc2\xa0\xf6\xd8B\xffP\x88/\x91\xd3]\x05\\\xf6M'
[(b':method', b'GET'), (b':scheme', b'https'), (b':path', b'/resource'), (b':authority', b'example.org')]
Discussion