Test_CORS_Origin_AllowCredentials() — fiber Function Reference
Architecture documentation for the Test_CORS_Origin_AllowCredentials() function in cors_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 1b9216ca_b622_6a9a_2e74_895245c22d24["Test_CORS_Origin_AllowCredentials()"] e59a43fd_cfa4_0f6b_1938_4a08e36ad74e["cors_test.go"] 1b9216ca_b622_6a9a_2e74_895245c22d24 -->|defined in| e59a43fd_cfa4_0f6b_1938_4a08e36ad74e style 1b9216ca_b622_6a9a_2e74_895245c22d24 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cors/cors_test.go lines 201–240
func Test_CORS_Origin_AllowCredentials(t *testing.T) {
t.Parallel()
// New fiber instance
app := fiber.New()
// OPTIONS (preflight) response headers when AllowOrigins is *
app.Use(New(Config{
AllowOrigins: []string{"http://localhost"},
AllowCredentials: true,
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, "http://localhost", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))
require.Equal(t, "true", 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.Set(fiber.HeaderOrigin, "http://localhost")
ctx.Request.Header.SetMethod(fiber.MethodGet)
handler(ctx)
require.Equal(t, "true", 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_Origin_AllowCredentials() do?
Test_CORS_Origin_AllowCredentials() is a function in the fiber codebase, defined in middleware/cors/cors_test.go.
Where is Test_CORS_Origin_AllowCredentials() defined?
Test_CORS_Origin_AllowCredentials() is defined in middleware/cors/cors_test.go at line 201.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free