Test_CORS_Wildcard() — fiber Function Reference
Architecture documentation for the Test_CORS_Wildcard() function in cors_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD bbc2304e_ca20_97d8_41b4_1217493f1c20["Test_CORS_Wildcard()"] e59a43fd_cfa4_0f6b_1938_4a08e36ad74e["cors_test.go"] bbc2304e_ca20_97d8_41b4_1217493f1c20 -->|defined in| e59a43fd_cfa4_0f6b_1938_4a08e36ad74e style bbc2304e_ca20_97d8_41b4_1217493f1c20 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cors/cors_test.go lines 159–198
func Test_CORS_Wildcard(t *testing.T) {
t.Parallel()
// New fiber instance
app := fiber.New()
// OPTIONS (preflight) response headers when AllowOrigins is *
app.Use(New(Config{
MaxAge: 3600,
ExposeHeaders: []string{"X-Request-ID"},
AllowHeaders: []string{"Authentication"},
}))
// Get handler pointer
handler := app.Handler()
// Make request
ctx := &fasthttp.RequestCtx{}
ctx.Request.SetRequestURI("/")
ctx.Request.Header.Set(fiber.HeaderOrigin, "http://localhost")
ctx.Request.Header.SetMethod(fiber.MethodOptions)
ctx.Request.Header.Set(fiber.HeaderAccessControlRequestMethod, fiber.MethodGet)
// Perform request
handler(ctx)
// Check result
require.Equal(t, "*", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin))) // Validates request is not reflecting origin in the response
require.Contains(t, string(ctx.Response.Header.Peek(fiber.HeaderVary)), fiber.HeaderOrigin, "Vary header should be set")
require.Empty(t, string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowCredentials)))
require.Equal(t, "3600", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlMaxAge)))
require.Equal(t, "Authentication", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowHeaders)))
// Test non OPTIONS (preflight) response headers
ctx = &fasthttp.RequestCtx{}
ctx.Request.Header.SetMethod(fiber.MethodGet)
ctx.Request.Header.Set(fiber.HeaderOrigin, "http://localhost")
handler(ctx)
require.NotContains(t, string(ctx.Response.Header.Peek(fiber.HeaderVary)), fiber.HeaderOrigin, "Vary header should not be set")
require.Empty(t, string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowCredentials)))
require.Equal(t, "X-Request-ID", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlExposeHeaders)))
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_CORS_Wildcard() do?
Test_CORS_Wildcard() is a function in the fiber codebase, defined in middleware/cors/cors_test.go.
Where is Test_CORS_Wildcard() defined?
Test_CORS_Wildcard() is defined in middleware/cors/cors_test.go at line 159.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free