Skip to content

fix(event-handler): handle CORS preflight OPTIONS in HttpResolverLocal#8268

Merged
leandrodamascena merged 2 commits into
aws-powertools:developfrom
Avinm:fix/http-resolver-local-cors-preflight
Jun 18, 2026
Merged

fix(event-handler): handle CORS preflight OPTIONS in HttpResolverLocal#8268
leandrodamascena merged 2 commits into
aws-powertools:developfrom
Avinm:fix/http-resolver-local-cors-preflight

Conversation

@Avinm

@Avinm Avinm commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Issue number: closes #8267

Summary

Changes

HttpResolverLocal was overriding _resolve_async, _call_route_async, _run_middleware_chain_async, and _handle_not_found_async, duplicating the parent's logic but without the CORS preflight branch present in ApiGatewayResolver._handle_not_found_async. OPTIONS requests fell through to the not-found handler and, if a generic @app.exception_handler(Exception) was registered, returned 500 with no CORS headers — blocking browser preflight checks.

Replaces all four overrides with a single thin _resolve_async that calls super()._resolve_async() and serializes the returned ResponseBuilder to dict for the ASGI layer. The parent already handles route matching, CORS preflight (OPTIONS → 204), not-found, and exception handling correctly.

User experience

Before: OPTIONS preflight to HttpResolverLocal with cors=CORSConfig(...) returns 500 with no CORS headers. Browser blocks the actual request.

After: OPTIONS preflight returns 204 with correct Access-Control-Allow-Origin and Access-Control-Allow-Methods headers, matching APIGatewayRestResolver behavior.


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

…figured

HttpResolverLocal overrode _resolve_async, _call_route_async,
_run_middleware_chain_async, and _handle_not_found_async, duplicating
the parent's logic without the CORS preflight branch. OPTIONS requests
fell through to the not-found handler and, if a generic exception handler
was registered, returned 500 with no CORS headers.

Replace all four overrides with a single thin _resolve_async that delegates
to super()._resolve_async() and serializes the returned ResponseBuilder to
dict. The parent already handles route matching, CORS preflight (OPTIONS →
204), not-found, and exception handling correctly.

Fixes aws-powertools#8267
@boring-cyborg

boring-cyborg Bot commented Jun 10, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 10, 2026
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.58%. Comparing base (1edc92e) to head (ea04b20).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8268      +/-   ##
===========================================
- Coverage    96.72%   96.58%   -0.14%     
===========================================
  Files          286      286              
  Lines        14347    14294      -53     
  Branches      1201     1192       -9     
===========================================
- Hits         13877    13806      -71     
- Misses         341      357      +16     
- Partials       129      131       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! APPROVED

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2026
@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena merged commit 603cdce into aws-powertools:develop Jun 18, 2026
15 checks passed
@boring-cyborg

boring-cyborg Bot commented Jun 18, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event_handlers size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: OPTIONS call returning 500 in HttpResolverLocal

2 participants