From 8906cd9678ecce8337bad2936aee583c9c221935 Mon Sep 17 00:00:00 2001 From: Tueem Date: Sun, 31 May 2026 13:12:57 +0200 Subject: [PATCH] fix(download): fix scheme determination behind reverse proxies --- internal/routes/download.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/routes/download.go b/internal/routes/download.go index c03d048..11566b1 100644 --- a/internal/routes/download.go +++ b/internal/routes/download.go @@ -104,9 +104,18 @@ func getPublicUrl(r *http.Request, subpath string) string { Host: r.Host, Path: path.Join("public", subpath), } - newURL.Scheme = "http" - if r.TLS != nil { - newURL.Scheme = "https" - } + newURL.Scheme = determineScheme(r) return newURL.String() } + +func determineScheme(r *http.Request) string { + if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { + return proto + } + + if r.TLS != nil { + return "https" + } + + return "http" +}