spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.52k stars 3.32k forks source link

Route CORS configuration does not work when properties are defined in Kebab case #3469

Closed siddhivinayak-sk closed 3 weeks ago

siddhivinayak-sk commented 3 months ago

Describe the bug When using CORS configuration on Route, it can be defined using metadata.cors property on route configuration as defined in documentation.

If properties are defined in Kebab case, it does not work as expected.

Sample

spring:
  cloud:
    gateway:
      routes:
      - id: cors_route
        uri: https://example.org
        predicates:
        - Path=/service/**
        metadata:
          cors:
            allowed-origins: '*'
            allowed-methods:
              - GET
              - POST
            allowed-headers: '*'
            max-age: 30

This is probably because CorsGatewayFilterApplicationListener's method private Optional<Object> findValue(Map<String, Object> metadata, String key) simply returns the value based on Keys which are only given in Camel case not Kebab case.

However, it works as expected when properties are defined in camel case but it look weird that some properties are only supported in camel case not Kebab case.

spencergibb commented 3 weeks ago

I'm afraid there isn't anything I can do because it is a map and not an object, so they are string keys and are case sensitive.