Skip to content

refactor(event-handler): simplify HTTP event parsing - #5686

Open
svozza wants to merge 3 commits into
mainfrom
refactor/http-event-parsing
Open

refactor(event-handler): simplify HTTP event parsing#5686
svozza wants to merge 3 commits into
mainfrom
refactor/http-event-parsing

Conversation

@svozza

@svozza svozza commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

The way we handle the incoming lambda event has always felt suboptimal to me, this refactor centralises API Gateway v1, v2, and ALB event conversion and reuses the converted event throughout the router. This refactor has the nice side effect of removing the awkward dance we had to do around rejecting invalid HTTP methods with a fake URL request. Also, base64 bodies are decoded directly to bytes so binary uploads are no longer corrupted by UTF-8 conversion. Lastly, I realised that proxyEventToWebRequest was erroneously made part of the public API originally: this refactor means it is no longer needed but unfortunately we cannot remove it so it is marked deprecated.

Changes

  • Share method, header, cookie, and body normalization while retaining source-specific URL construction.
  • Return early 405 responses without fabricating a request context.
  • Preserve ordinary string bodies; decoded base64 bodies without a Content-Type header now leave it unset.
  • Deprecate proxyEventToWebRequest in favor of accessing reqCtx.req in Router handlers or middleware.
  • Document request-body handling and add regression tests for binary and multipart uploads, validation, URLs, cookies, and error boundaries.

Compared with the implementation proposed in #5685:

  • Use the Web Request itself as the normalized representation, rather than introducing RawRequest and HttpRequestInput. Shared functions centralize normalization without additional intermediate objects.
  • Preserve existing source-specific URL construction and inbound header merging/deduplication behavior. Changing those semantics requires separate compatibility decisions.
  • Defer the outbound response projections and response-header/streaming fixes to Bug: Set-Cookie and multi-value header conversion drops, splits and collapses response headers in the HTTP event handler #5674. This PR focuses on inbound conversion and reusing event classification.

Issue number: closes #5685


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/XL PRs between 500-999 LOC, often PRs that grown with feedback label Sep 9, 2026
@svozza
svozza requested a review from dreamorosi September 9, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL PRs between 500-999 LOC, often PRs that grown with feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintenance: parse API Gateway and ALB events into a canonical request shape at the edge of the HTTP event handler

2 participants