Skip to content

Commit a6f4c13

Browse files
authored
fix(middleware/cors): Vary header handling non-cors OPTIONS requests (#2939)
* fix(middleware/cors): Vary header handling non-cors OPTIONS requests * chore(middleware/cors): Add Vary header for non-CORS OPTIONS requests comment
1 parent e574c0d commit a6f4c13

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

middleware/cors/cors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ func New(config ...Config) fiber.Handler {
175175

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

0 commit comments

Comments
 (0)