Fix perfect match missed for headers with empty values#287
Open
bysiber wants to merge 1 commit intopython-hyper:masterfrom
Open
Fix perfect match missed for headers with empty values#287bysiber wants to merge 1 commit intopython-hyper:masterfrom
bysiber wants to merge 1 commit intopython-hyper:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HeaderTable.search()returns(index, name, value)for perfect matches and(index, name, None)for partial matches. The encoder distinguishes them withif perfect:, but this check fails whenvalueisb""because empty bytes are falsy in Python.46 of 61 static table entries have an empty value (
:authority,accept-charset,accept-language,age,allow,authorization,cache-control, etc.). When encoding a header that perfectly matches one of those entries, the encoder falls through to the indexed-literal branch instead:Expected:
81(indexed representation, 1 byte, no dynamic table entry).The indexed-literal path also calls
self.header_table.add(name, value), which adds an unnecessary duplicate of the static entry to the dynamic table, wasting space and evicting useful entries.This changes
if perfect:toif perfect is not None:.