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.54k stars 3.33k forks source link

globalcors.corsConfigurations.[/].maxAge configuation not work #1053

Closed xiongchun closed 5 years ago

xiongchun commented 5 years ago

i set my cors in application.yml as follows,

      globalcors: 
        corsConfigurations: 
          '[/**]':
            #allowedOrigins: "http://127.0.0.1:8848"
            allowedOrigins: "*"
            maxAge: 86400
            allowedMethods:
            - GET
            - POST

but, unfortunately the "Access-Control-Max-Age" did not appear in response header。

Access-Control-Allow-Origin: *
Content-Type: application/json;charset=UTF-8
Date: Fri, 10 May 2019 07:37:02 GMT
transfer-encoding: chunked
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
X-RateLimit-Burst-Capacity: 5000
X-RateLimit-Remaining: 4999
X-RateLimit-Replenish-Rate: 5000
tony-clarke-amdocs commented 5 years ago

The access-control-max-age should only appear in a pre-flight request response. I guess your request was not a preflight request. A request is a preflight request if:

  1. HTTP method is Options
  2. Origin header is not null
  3. Access-Control-Request-Method header is not null
xiongchun commented 5 years ago

@tony-clarke-amdocs thanks. i learn a lot from your reply.