MCPcopy
hub / github.com/gofiber/fiber / setSimpleHeaders

Function setSimpleHeaders

middleware/cors/cors.go:209–232  ·  view source on GitHub ↗

Function to set Simple CORS headers

(c fiber.Ctx, allowOrigin string, cfg *Config)

Source from the content-addressed store, hash-verified

207
208// Function to set Simple CORS headers
209func setSimpleHeaders(c fiber.Ctx, allowOrigin string, cfg *Config) {
210 if cfg == nil {
211 return
212 }
213
214 if cfg.AllowCredentials {
215 // When AllowCredentials is true, set the Access-Control-Allow-Origin to the specific origin instead of '*'
216 if allowOrigin == "*" {
217 c.Set(fiber.HeaderAccessControlAllowOrigin, allowOrigin)
218 log.Warn("[CORS] 'AllowCredentials' is true, but 'AllowOrigins' cannot be set to '*'.")
219 } else if allowOrigin != "" {
220 c.Set(fiber.HeaderAccessControlAllowOrigin, allowOrigin)
221 c.Set(fiber.HeaderAccessControlAllowCredentials, "true")
222 }
223 } else if allowOrigin != "" {
224 // For non-credential requests, it's safe to set to '*' or specific origins
225 c.Set(fiber.HeaderAccessControlAllowOrigin, allowOrigin)
226 }
227
228 // Set Expose-Headers if not empty
229 if len(cfg.ExposeHeaders) > 0 {
230 c.Set(fiber.HeaderAccessControlExposeHeaders, strings.Join(cfg.ExposeHeaders, ", "))
231 }
232}
233
234// Function to set Preflight CORS headers
235func setPreflightHeaders(c fiber.Ctx, allowOrigin, maxAge string, cfg *Config) {

Callers 4

NewFunction · 0.85
setPreflightHeadersFunction · 0.85

Calls 2

WarnFunction · 0.92
SetMethod · 0.65