perf(aws-lambda)!: read event headers once when parsing the body, remove getEventHeader - #132
Conversation
…ove `getEventHeader` `toStandardBody` called `getEventHeader` six times, and every call lowercased and scanned every header key (both `multiValueHeaders` and `headers` on payload format 1.0). It now builds the header map once with `toStandardHeaders` and reads each header from it, about 1.5-1.7x faster on a 20-header event. `getEventHeader` had no remaining callers and repeated the merge rules of `toStandardHeaders` with slightly different results, so it is removed. BREAKING CHANGE: `getEventHeader` is no longer exported from `@standard-server/aws-lambda`. Use `toStandardHeaders(event)[key.toLowerCase()]`. Co-Authored-By: Claude <noreply@anthropic.com>
@standard-server/aws-lambda
@standard-server/core
@standard-server/fastify
@standard-server/fetch
@standard-server/node
@standard-server/peer
@standard-server/shared
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Read event headers once —
toStandardBodyreplaces fourgetEventHeaderscans with a singletoStandardHeaders(event)and derives the body hint pluscontent-type/content-dispositionfrom it (packages/aws-lambda/src/body.ts:23). getEventHeaderremoved — the export and its five tests are gone; the cookie-over-cookiespriority it uniquely covered is re-tested ontoStandardHeaders(packages/aws-lambda/src/headers.ts,headers.test.ts).- Fallback coverage —
toStandardBodyis now exercised with a v1 event whose content headers live only inheadersand with a v2 event (body.test.ts). - README drops
getEventHeaderfrom the lower-level helpers row.
The refactor is behavior-preserving for body parsing: single multi-value reads normalize identically through flattenStandardHeader, multiValueHeaders still wins per key, and both implementations skip empty/undefined values. The two documented divergences (single-value 1.0 entries as string not [string], case-variant 1.0 keys merging) only affect external getEventHeader callers or pathological events, and are called out in the PR description. Verified locally at this head: vitest run packages/aws-lambda → 98 passed, repo type:check clean, eslint clean.
DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏

toStandardBodyin the aws-lambda adapter now reads each Lambda event's headers once, instead of scanning every header key six times. Body parsing's header work is about 1.5–1.7x faster on a typical 20-header event.getEventHeader, which nothing used any more, is removed from the public API.Performance
Breaking change
getEventHeaderis no longer exported from@standard-server/aws-lambda. Replace it withtoStandardHeaders(event)[key.toLowerCase()]. The result differs in two edge cases: a single-value 1.0multiValueHeadersentry comes back as a string instead of a one-item array, and 1.0 header keys that differ only in case are merged instead of first-match.Testing
headers, and with 2.0 events.getEventHeader(acookieheader takes priority over the 2.0cookiesfield) is now tested ontoStandardHeaders.headers.tsstays at 100% coverage.