From 09222a116ff1ebf45b06f2f4cbd821e8009da9a1 Mon Sep 17 00:00:00 2001 From: orangix Date: Mon, 5 Jan 2026 08:05:49 +0100 Subject: [PATCH] implement x-forwarded-proto --- utils/config.go | 30 ++++++++++++++++-------------- utils/getUrl.go | 9 ++++++--- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/utils/config.go b/utils/config.go index 4661035..1749827 100644 --- a/utils/config.go +++ b/utils/config.go @@ -6,15 +6,16 @@ import ( ) type config struct { - Port string - Addr string - ImgurId string - Secure bool - FiberPrefork bool - ImageCache bool - CleanupInterval time.Duration - CacheDir string - Privacy map[string]interface{} + Port string + Addr string + ImgurId string + ProtocolDetection bool + Secure bool + FiberPrefork bool + ImageCache bool + CleanupInterval time.Duration + CacheDir string + Privacy map[string]interface{} } var Config config @@ -45,11 +46,12 @@ func LoadConfig() { } Config = config{ - Port: port, - Addr: addr, - ImgurId: imgurId, - Secure: os.Getenv("SECURE") == "true", - FiberPrefork: os.Getenv("FIBER_PREFORK") == "true", + Port: port, + Addr: addr, + ImgurId: imgurId, + ProtocolDetection: os.Getenv("PROTOCOL_DETECTION") == "true" || os.Getenv("PROTOCOL_DETECTION") == "1", + Secure: os.Getenv("SECURE") == "true", + FiberPrefork: os.Getenv("FIBER_PREFORK") == "true", Privacy: map[string]interface{}{ "set": os.Getenv("PRIVACY_NOT_COLLECTED") != "", "policy": os.Getenv("PRIVACY_POLICY"), diff --git a/utils/getUrl.go b/utils/getUrl.go index 4b3a96c..bf47a56 100644 --- a/utils/getUrl.go +++ b/utils/getUrl.go @@ -3,9 +3,12 @@ package utils import "github.com/gofiber/fiber/v2" func GetInstanceUrl(c *fiber.Ctx) string { - proto := "https://" + proto := "https" if !Config.Secure { - proto = "http://" + proto = "http" } - return proto + c.Hostname() + if Config.ProtocolDetection { + proto = c.Get("X-Forwarded-Proto", proto) + } + return proto + "://" + c.Hostname() }