Merge pull request 'implement x-forwarded-proto' (#239) from x-forwarded-for into main

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/239
Reviewed-by: video-prize-ranch <video-prize-ranch@noreply.codeberg.org>
This commit is contained in:
orangix
2026-01-06 04:55:44 +01:00
2 changed files with 22 additions and 17 deletions

View File

@@ -6,15 +6,16 @@ import (
) )
type config struct { type config struct {
Port string Port string
Addr string Addr string
ImgurId string ImgurId string
Secure bool ProtocolDetection bool
FiberPrefork bool Secure bool
ImageCache bool FiberPrefork bool
CleanupInterval time.Duration ImageCache bool
CacheDir string CleanupInterval time.Duration
Privacy map[string]interface{} CacheDir string
Privacy map[string]interface{}
} }
var Config config var Config config
@@ -45,11 +46,12 @@ func LoadConfig() {
} }
Config = config{ Config = config{
Port: port, Port: port,
Addr: addr, Addr: addr,
ImgurId: imgurId, ImgurId: imgurId,
Secure: os.Getenv("SECURE") == "true", ProtocolDetection: os.Getenv("PROTOCOL_DETECTION") == "true" || os.Getenv("PROTOCOL_DETECTION") == "1",
FiberPrefork: os.Getenv("FIBER_PREFORK") == "true", Secure: os.Getenv("SECURE") == "true",
FiberPrefork: os.Getenv("FIBER_PREFORK") == "true",
Privacy: map[string]interface{}{ Privacy: map[string]interface{}{
"set": os.Getenv("PRIVACY_NOT_COLLECTED") != "", "set": os.Getenv("PRIVACY_NOT_COLLECTED") != "",
"policy": os.Getenv("PRIVACY_POLICY"), "policy": os.Getenv("PRIVACY_POLICY"),

View File

@@ -3,9 +3,12 @@ package utils
import "github.com/gofiber/fiber/v2" import "github.com/gofiber/fiber/v2"
func GetInstanceUrl(c *fiber.Ctx) string { func GetInstanceUrl(c *fiber.Ctx) string {
proto := "https://" proto := "https"
if !Config.Secure { 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()
} }