transport/http: direct header insertion on HTTP/2 outbound - #2484
Open
bananacocodrilo wants to merge 1 commit into
Open
transport/http: direct header insertion on HTTP/2 outbound#2484bananacocodrilo wants to merge 1 commit into
bananacocodrilo wants to merge 1 commit into
Conversation
bananacocodrilo
force-pushed
the
http2-direct-header-injection
branch
from
May 11, 2026 14:35
9c73877 to
9af0395
Compare
bananacocodrilo
force-pushed
the
http2-direct-header-injection
branch
from
July 14, 2026 16:07
9af0395 to
d436036
Compare
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.
RELEASE NOTES:
On HTTP/2, header field names are always lowercased on the wire (RFC 7540 §8.1.2), so the canonicalization that
net/httpperforms viatextproto.CanonicalMIMEHeaderKeyon everyhttp.Header.Set/Addcall is redundant and only adds CPU and allocations.This PR introduces a fast path on the HTTP/2 outbound that writes directly into the underlying
http.Headermap, bypassing canonicalization in three hot spots:headerMapper.ToHTTPHeadersPreserveCasewithCoreHeaders(gated byo.useHTTP2)directHTTPHeadersCarrierThe HTTP/1.1 path is unchanged and continues to canonicalize header names, preserving backward compatibility with peers that perform case-sensitive header matching.
Why it's safe
http.Header.Set/Addandopentracing.HTTPHeadersCarrierAddHeader(setup-time)http.Header.Add; not a hot pathCallerHeader,ServiceHeader, …)Rpc-Caller,Rpc-Service, …)Wire-format implications
uber-trace-id) instead of the canonicalized form (Uber-Trace-Id). On the wire it's still lowercase per HTTP/2 spec.Performance
Benchmarks on Apple M2 Max,
count=6, fullcreateRequest+withCoreHeaderspath. Median of 6 runs.Bytes allocated drop 4–11% across scenarios.