Class CorsGatewayFilterApplicationListener

java.lang.Object
org.springframework.cloud.gateway.filter.cors.CorsGatewayFilterApplicationListener
All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationListener<RefreshRoutesResultEvent>

public class CorsGatewayFilterApplicationListener extends Object implements org.springframework.context.ApplicationListener<RefreshRoutesResultEvent>

For each Route, this listener inspects its predicates and looks for an instance of PathRoutePredicateFactory. If a path predicate is found, the first defined path pattern is extracted and used as the key for associating the route-specific CorsConfiguration.

After collecting all route-level CORS configurations, the listener merges them with globally defined configurations from GlobalCorsProperties, ensuring that route-specific configurations take precedence over global ones in case of conflicts (e.g., both defining CORS rules for /**).

The merged configuration map is then applied to the RoutePredicateHandlerMapping via setCorsConfigurations.

Note: A LinkedHashMap is used to store the merged configurations to preserve insertion order, which ensures predictable CORS resolution when multiple path patterns could match a request.

Author:
Fredrich Ombico, Abel Salgado Romero, Yavor Chamov