From 747503692fdd4a93cd601209846451ada8883983 Mon Sep 17 00:00:00 2001 From: Jason McNeil Date: Mon, 18 Mar 2024 11:30:34 -0300 Subject: [PATCH] fix(middleware/cors): Update Next function signature --- docs/api/middleware/cors.md | 2 +- middleware/cors/cors.go | 4 ++-- middleware/cors/cors_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/middleware/cors.md b/docs/api/middleware/cors.md index 8a85271aa3..b524c4c59f 100644 --- a/docs/api/middleware/cors.md +++ b/docs/api/middleware/cors.md @@ -112,7 +112,7 @@ panic: [CORS] 'AllowCredentials' is true, but 'AllowOrigins' cannot be set to `" | Property | Type | Description | Default | |:-----------------|:---------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------| -| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` | +| Next | `func(fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` | | AllowOriginsFunc | `func(origin string) bool` | `AllowOriginsFunc` is a function that dynamically determines whether to allow a request based on its origin. If this function returns `true`, the 'Access-Control-Allow-Origin' response header will be set to the request's 'origin' header. This function is only used if the request's origin doesn't match any origin in `AllowOrigins`. | `nil` | | AllowOrigins | `string` | AllowOrigins defines a comma separated list of origins that may access the resource. This supports subdomain matching, so you can use a value like "https://*.example.com" to allow any subdomain of example.com to submit requests. | `"*"` | | AllowMethods | `string` | AllowMethods defines a list of methods allowed when accessing the resource. This is used in response to a preflight request. | `"GET,POST,HEAD,PUT,DELETE,PATCH"` | diff --git a/middleware/cors/cors.go b/middleware/cors/cors.go index 3cc6f4fa9f..ba7e917003 100644 --- a/middleware/cors/cors.go +++ b/middleware/cors/cors.go @@ -13,7 +13,7 @@ type Config struct { // Next defines a function to skip this middleware when returned true. // // Optional. Default: nil - Next func(c *fiber.Ctx) bool + Next func(c fiber.Ctx) bool // AllowOriginsFunc defines a function that will set the 'Access-Control-Allow-Origin' // response header to the 'origin' request header when returned true. This allows for @@ -165,7 +165,7 @@ func New(config ...Config) fiber.Handler { // Return new handler return func(c fiber.Ctx) error { // Don't execute middleware if Next returns true - if cfg.Next != nil && cfg.Next(&c) { + if cfg.Next != nil && cfg.Next(c) { return c.Next() } diff --git a/middleware/cors/cors_test.go b/middleware/cors/cors_test.go index 43a58c811a..2e80ca1c6b 100644 --- a/middleware/cors/cors_test.go +++ b/middleware/cors/cors_test.go @@ -422,7 +422,7 @@ func Test_CORS_Next(t *testing.T) { t.Parallel() app := fiber.New() app.Use(New(Config{ - Next: func(_ *fiber.Ctx) bool { + Next: func(_ fiber.Ctx) bool { return true }, }))