Commit bb5c41a
committed
Remove redundant CanonicalizeHeaderKey from metadata iteration paths
Problem:
metadataToTransportRequest and getApplicationHeaders both call
transport.CanonicalizeHeaderKey (strings.ToLower) on every key while
iterating gRPC metadata.MD. These keys are already guaranteed to be
lowercase, making the calls redundant CPU work on every inbound and
response path.
Fix:
Remove the CanonicalizeHeaderKey call from both functions. Also
normalize a test case in TestGetApplicationHeaders that used a
mixed-case metadata key via a raw metadata.MD literal, which no
longer reflects a realistic scenario.
Safety — three independent guarantees that metadata keys are lowercase:
1. HTTP/2 spec (RFC 7540 s8.1.2): header field names MUST be
converted to lowercase prior to their encoding in HTTP/2.
The requirement is on the sender; receivers are guaranteed
to see lowercase keys on the wire.
https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2
2. grpc-go PR #4416 (merged v1.39, June 2021): FromIncomingContext
now explicitly lowercases all keys, including those injected by
interceptors.
grpc/grpc-go#4416
3. yarpc-go uses grpc-go v1.67.3 (go.mod), well past v1.39.
Call sites:
- metadataToTransportRequest: called from handler.go via
metadata.FromIncomingContext (server inbound path)
- getApplicationHeaders: called from outbound.go with response
trailer metadata (client response path)
Impact:
Eliminates one strings.ToLower scan per metadata entry on both the
server inbound and client response paths.
Made-with: Cursor1 parent cccfbde commit bb5c41a
2 files changed
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
| 150 | + | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
| |||
223 | 222 | | |
224 | 223 | | |
225 | 224 | | |
226 | | - | |
| 225 | + | |
227 | 226 | | |
228 | 227 | | |
229 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
0 commit comments