Skip to content

Commit

Permalink
fix(middleware/cors): Vary header handling non-cors OPTIONS requests (#…
Browse files Browse the repository at this point in the history
…2939)

* fix(middleware/cors): Vary header handling non-cors OPTIONS requests

* chore(middleware/cors): Add Vary header for non-CORS OPTIONS requests comment
  • Loading branch information
sixcolors committed Mar 26, 2024
1 parent e574c0d commit a6f4c13
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions middleware/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ func New(config ...Config) fiber.Handler {

// If it's a preflight request and doesn't have Access-Control-Request-Method header, it's outside the scope of CORS
if c.Method() == fiber.MethodOptions && c.Get(fiber.HeaderAccessControlRequestMethod) == "" {
// Response to OPTIONS request should not be cached but,
// some caching can be configured to cache such responses.
// To Avoid poisoning the cache, we include the Vary header
// for non-CORS OPTIONS requests:
c.Vary(fiber.HeaderOrigin)
return c.Next()
}

Expand Down

0 comments on commit a6f4c13

Please sign in to comment.