Skip to content

Commit 89cce96

Browse files
bysiberKriechi
authored andcommitted
Fix perfect match missed for headers with empty values
HeaderTable.search() returns (index, name, value) for perfect matches and (index, name, None) for partial matches. The encoder distinguishes them with `if perfect:`, but this fails when value is b"" because empty bytes are falsy in Python. 46 of 61 static table entries have an empty value (e.g. :authority, accept-charset, accept-language, age, allow, …). When encoding a header that perfectly matches one of these entries, the encoder falls through to the indexed-literal path — using 2+ bytes instead of 1 and unnecessarily adding the entry to the dynamic table. Change the check to `if perfect is not None:` so that b"" is treated as a valid perfect match.
1 parent 1621490 commit 89cce96

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/hpack/hpack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def add(self, to_add: tuple[bytes, bytes], sensitive: bool, huffman: bool = Fals
320320
# can use the indexed literal.
321321
index, name, perfect = match
322322

323-
if perfect:
323+
if perfect is not None:
324324
# Indexed representation.
325325
encoded = self._encode_indexed(index)
326326
else:

0 commit comments

Comments
 (0)