1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-16 02:52:45 +00:00

fix cors * behavior #2338 (#2339)

🐛- fix cors * behavior #2338
This commit is contained in:
Ryan Devenney 2023-02-20 16:36:34 -05:00 committed by GitHub
parent 497eb02b48
commit b634ba0a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -112,11 +112,11 @@ func New(config ...Config) fiber.Handler {
// Check allowed origins
for _, o := range allowOrigins {
if o == "*" && cfg.AllowCredentials {
allowOrigin = origin
if o == "*" {
allowOrigin = "*"
break
}
if o == "*" || o == origin {
if o == origin {
allowOrigin = o
break
}

View File

@ -76,7 +76,7 @@ func Test_CORS_Wildcard(t *testing.T) {
handler(ctx)
// Check result
utils.AssertEqual(t, "localhost", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))
utils.AssertEqual(t, "*", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))
utils.AssertEqual(t, "true", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowCredentials)))
utils.AssertEqual(t, "3600", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlMaxAge)))
utils.AssertEqual(t, "Authentication", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowHeaders)))