Skip to content

Commit 55fb979

Browse files
committed
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 7b9a7fc commit 55fb979

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/hpack/hpack.py

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

316-
if perfect:
316+
if perfect is not None:
317317
# Indexed representation.
318318
encoded = self._encode_indexed(index)
319319
else:

0 commit comments

Comments
 (0)