add protocol to cache key (#241)

fixes #240

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/241
Reviewed-by: video-prize-ranch <video-prize-ranch@noreply.codeberg.org>
Co-authored-by: orangix <uleo8b8g@anonaddy.me>
Co-committed-by: orangix <uleo8b8g@anonaddy.me>
This commit is contained in:
orangix
2026-01-12 01:45:24 +01:00
committed by video-prize-ranch
parent 107a45e58b
commit e8ed026962
2 changed files with 8 additions and 4 deletions

View File

@@ -11,13 +11,13 @@ import (
"codeberg.org/rimgo/rimgo/static" "codeberg.org/rimgo/rimgo/static"
"codeberg.org/rimgo/rimgo/utils" "codeberg.org/rimgo/rimgo/utils"
"codeberg.org/rimgo/rimgo/views" "codeberg.org/rimgo/rimgo/views"
"github.com/mailgun/raymond/v2"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache" "github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/filesystem" "github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/recover" "github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/template/handlebars/v2" "github.com/gofiber/template/handlebars/v2"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/mailgun/raymond/v2"
) )
func main() { func main() {
@@ -96,7 +96,7 @@ func main() {
Expiration: 30 * time.Minute, Expiration: 30 * time.Minute,
MaxBytes: 25000000, MaxBytes: 25000000,
KeyGenerator: func(c *fiber.Ctx) string { KeyGenerator: func(c *fiber.Ctx) string {
return c.OriginalURL() return utils.GetInstanceProtocol(c) + " " + c.OriginalURL()
}, },
CacheControl: true, CacheControl: true,
StoreResponseHeaders: true, StoreResponseHeaders: true,

View File

@@ -2,7 +2,7 @@ package utils
import "github.com/gofiber/fiber/v2" import "github.com/gofiber/fiber/v2"
func GetInstanceUrl(c *fiber.Ctx) string { func GetInstanceProtocol(c *fiber.Ctx) string {
proto := "https" proto := "https"
if !Config.Secure { if !Config.Secure {
proto = "http" proto = "http"
@@ -10,5 +10,9 @@ func GetInstanceUrl(c *fiber.Ctx) string {
if Config.ProtocolDetection { if Config.ProtocolDetection {
proto = c.Get("X-Forwarded-Proto", proto) proto = c.Get("X-Forwarded-Proto", proto)
} }
return proto + "://" + c.Hostname() return proto
}
func GetInstanceUrl(c *fiber.Ctx) string {
return GetInstanceProtocol(c) + "://" + c.Hostname()
} }