feat(controller): Expose rate limiting headers via CORS (#4159)

This adds a Access-Control-Expose-Headers response header to an Options
request to allow the rate limiting related headers to be accessible via
requests that are subject to CORS.
This commit is contained in:
Timothy Messier authored and GitHub committed 2024-01-08 10:02:36 -05:00
1 parent 0823e395a6
commit b3bc367534
2 files changed
+8

No files matched your search

+7
View File
@@ -499,6 +499,12 @@ func wrapHandlerWithCors(h http.Handler, props HandlerProperties) http.Handler {
"Authorization",
}, props.ListenerConfig.CorsAllowedHeaders...)
allowedResponseHeaders := strings.Join([]string{
"Retry-After",
"RateLimit",
"RateLimit-Policy",
}, ", ")
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if props.ListenerConfig.CorsEnabled == nil || !*props.ListenerConfig.CorsEnabled {
h.ServeHTTP(w, req)
@@ -548,6 +554,7 @@ func wrapHandlerWithCors(h http.Handler, props HandlerProperties) http.Handler {
w.Header().Set("Access-Control-Allow-Origin", origin)
w.Header().Set("Vary", "Origin")
w.Header().Set("Access-Control-Expose-Headers", allowedResponseHeaders)
// Apply headers for preflight requests
if req.Method == http.MethodOptions {