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

Function New

middleware/hostauthorization/hostauthorization.go:286–306  ·  view source on GitHub ↗

New creates a new host authorization middleware handler.

(config ...Config)

Source from the content-addressed store, hash-verified

284
285// New creates a new host authorization middleware handler.
286func New(config ...Config) fiber.Handler {
287 cfg := configDefault(config...)
288 parsed := parseAllowedHosts(cfg.AllowedHosts)
289
290 return func(c fiber.Ctx) error {
291 if cfg.Next != nil && cfg.Next(c) {
292 return c.Next()
293 }
294
295 host, ok := parseNormalizedAuthority(c.Host())
296 if !ok {
297 return cfg.ErrorHandler(c, ErrForbiddenHost)
298 }
299
300 if matchHost(host, parsed, cfg.AllowedHostsFunc) {
301 return c.Next()
302 }
303
304 return cfg.ErrorHandler(c, ErrForbiddenHost)
305 }
306}

Calls 7

parseAllowedHostsFunction · 0.85
parseNormalizedAuthorityFunction · 0.85
matchHostFunction · 0.85
ErrorHandlerMethod · 0.80
configDefaultFunction · 0.70
NextMethod · 0.65
HostMethod · 0.65