Skip to content

Refactor route-specific CORS to be route-bound instead of path-bound#4131

Open
qnnn wants to merge 2 commits intospring-cloud:mainfrom
qnnn:main
Open

Refactor route-specific CORS to be route-bound instead of path-bound#4131
qnnn wants to merge 2 commits intospring-cloud:mainfrom
qnnn:main

Conversation

@qnnn
Copy link
Copy Markdown
Contributor

@qnnn qnnn commented Apr 2, 2026

Summary

​ This PR refactors the route-specific CORS implementation by moving the logic from CorsGatewayFilterApplicationListener into RoutePredicateHandlerMapping#getCorsConfiguration.

Problem

​ The current implementation of route-specific CORS is not actually bound to the route, but to the path predicate. This approach:

  • Does not follow Spring's AbstractHandlerMapping#getHandler combine design pattern
  • Cannot support independent CORS configurations for multiple routes sharing the same path predicate (e.g., two routes with Path=/api/** but different host predicates)

Solution

​ Instead of pre-populating CORS configurations by path at startup, the new implementation reads CORS configuration directly from the matched route's metadata during request processing.

Move CORS configuration reading from CorsGatewayFilterApplicationListener (pre-populated at startup by path) to RoutePredicateHandlerMapping#getCorsConfiguration (read from route metadata during request). This allows independent CORS configurations for multiple routes sharing the same path predicate.

Signed-off-by: qnnn <qiunan@cmbchina.com>
…EndpointRedisRefreshTest.

Signed-off-by: qnnn <qiunan@cmbchina.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants