From e8ed026962921c2e557a66203969c51d50c3b8ec Mon Sep 17 00:00:00 2001 From: orangix Date: Mon, 12 Jan 2026 01:45:24 +0100 Subject: [PATCH] add protocol to cache key (#241) fixes #240 Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/241 Reviewed-by: video-prize-ranch Co-authored-by: orangix Co-committed-by: orangix --- main.go | 4 ++-- utils/getUrl.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 88f344c..23bb2e5 100644 --- a/main.go +++ b/main.go @@ -11,13 +11,13 @@ import ( "codeberg.org/rimgo/rimgo/static" "codeberg.org/rimgo/rimgo/utils" "codeberg.org/rimgo/rimgo/views" - "github.com/mailgun/raymond/v2" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cache" "github.com/gofiber/fiber/v2/middleware/filesystem" "github.com/gofiber/fiber/v2/middleware/recover" "github.com/gofiber/template/handlebars/v2" "github.com/joho/godotenv" + "github.com/mailgun/raymond/v2" ) func main() { @@ -96,7 +96,7 @@ func main() { Expiration: 30 * time.Minute, MaxBytes: 25000000, KeyGenerator: func(c *fiber.Ctx) string { - return c.OriginalURL() + return utils.GetInstanceProtocol(c) + " " + c.OriginalURL() }, CacheControl: true, StoreResponseHeaders: true, diff --git a/utils/getUrl.go b/utils/getUrl.go index bf47a56..8c3ddec 100644 --- a/utils/getUrl.go +++ b/utils/getUrl.go @@ -2,7 +2,7 @@ package utils import "github.com/gofiber/fiber/v2" -func GetInstanceUrl(c *fiber.Ctx) string { +func GetInstanceProtocol(c *fiber.Ctx) string { proto := "https" if !Config.Secure { proto = "http" @@ -10,5 +10,9 @@ func GetInstanceUrl(c *fiber.Ctx) string { if Config.ProtocolDetection { proto = c.Get("X-Forwarded-Proto", proto) } - return proto + "://" + c.Hostname() + return proto +} + +func GetInstanceUrl(c *fiber.Ctx) string { + return GetInstanceProtocol(c) + "://" + c.Hostname() }