From b99b833740953911f6ce1589193ef0e61aec34f7 Mon Sep 17 00:00:00 2001 From: Viktor Persson Date: Sat, 28 May 2022 00:05:29 +0200 Subject: [PATCH 1/2] Refactor favicon middleware, avoid magic numbers. --- middleware/favicon/favicon.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/middleware/favicon/favicon.go b/middleware/favicon/favicon.go index c2d12b32a3..fe9f551a07 100644 --- a/middleware/favicon/favicon.go +++ b/middleware/favicon/favicon.go @@ -97,7 +97,8 @@ func New(config ...Config) fiber.Handler { } // Only respond to favicon requests - if len(c.Path()) != 12 || c.Path() != "/favicon.ico" { + standardPath := "/favicon.ico" + if len(c.Path()) != len(standardPath) || c.Path() != standardPath { return c.Next() } From 3a443246de81c8375d889cfab596367083a01896 Mon Sep 17 00:00:00 2001 From: Viktor Persson Date: Sat, 28 May 2022 09:28:55 +0200 Subject: [PATCH 2/2] Introduce constant for path to favicon. --- middleware/favicon/favicon.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/middleware/favicon/favicon.go b/middleware/favicon/favicon.go index fe9f551a07..5f7bcbfbb0 100644 --- a/middleware/favicon/favicon.go +++ b/middleware/favicon/favicon.go @@ -40,6 +40,7 @@ var ConfigDefault = Config{ } const ( + fPath = "/favicon.ico" hType = "image/x-icon" hAllow = "GET, HEAD, OPTIONS" hZero = "0" @@ -97,8 +98,7 @@ func New(config ...Config) fiber.Handler { } // Only respond to favicon requests - standardPath := "/favicon.ico" - if len(c.Path()) != len(standardPath) || c.Path() != standardPath { + if c.Path() != fPath { return c.Next() }