Skip to content

feat: Add CORS preflight handler#100

Merged
thced merged 12 commits into
masterfrom
feat/cors-handler
May 26, 2026
Merged

feat: Add CORS preflight handler#100
thced merged 12 commits into
masterfrom
feat/cors-handler

Conversation

@thced

@thced thced commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds Handlers.corsPreflightHandler(...) with two overloads (List<String> of origins and Predicate<String>) for answering CORS OPTIONS preflight requests; wire via extraRoute("/api/**", ...).
  • 22 unit tests covering happy path, optional-header omission, all 4xx rejection branches, case-insensitive header matching, and constructor validation.
  • README "CORS preflight" subsection with usage example.

Test plan

  • mvn verify passes (68 IT, 0 failures)
  • CorsPreflightHandlerTest 22/22 green

thced added 12 commits May 25, 2026 12:02
Reduce cognitive complexity of the predicate corsPreflightHandler overload
by extracting requireHeader / isPreflightAllowed / parseMethodOrNull /
requestedHeadersAllowed / buildPreflightSuccess helpers. Introduce an ALLOW
constant for the repeated header name. Mark the swallowed parse exception
with an unnamed pattern. Hoist throwing argument expressions out of
assertThatThrownBy lambdas so each lambda has a single risky call.
Move corsPreflightHandler out of Handlers into a dedicated Cors class
with the simpler API Cors.preflightHandler(...). The Handlers class is
left to truly handler-shaped factories (alive, health, resource,
default exception handler). Renames CorsPreflightHandlerTest to
CorsTest. README and call sites updated accordingly.
@sonarqubecloud

Copy link
Copy Markdown

@thced thced merged commit 947758c into master May 26, 2026
6 checks passed
@thced thced deleted the feat/cors-handler branch May 26, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant