fix(ffi): preserve header order when replacing values - #4160
Open
freedom-winds wants to merge 1 commit into
Open
fix(ffi): preserve header order when replacing values#4160freedom-winds wants to merge 1 commit into
freedom-winds wants to merge 1 commit into
Conversation
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.
During a static audit of the FFI header APIs and their header-order preservation logic, I found that hyper_headers_set() could leave header values and ordering metadata in an inconsistent state after replacing a multi-value header.
hyper_headers_set()usesHeaderMap::insert(), which removes all existing values for a header name and stores a single replacement value. However,OriginalHeaderOrder::insert()previously did not update num_entries or remove existing (HeaderName, index) order entries when that header name already existed.For example, after adding:
Set-Cookie: a=b
Content-Encoding: gzip
Set-Cookie: c=d
X-After: present
and then calling hyper_headers_set("Set-Cookie", "replacement"), the header map contains only one Set-Cookie value, but the ordering metadata still contains an entry for the old second value. When hyper_headers_foreach() reaches that stale index, it stops iteration early and silently omits later headers such as X-After.
The fix updates OriginalHeaderOrder::insert() so that replacement: