diff --git a/pkg/s3-proxy/server/utils/utils.go b/pkg/s3-proxy/server/utils/utils.go index c50ac92e..ae540d5f 100644 --- a/pkg/s3-proxy/server/utils/utils.go +++ b/pkg/s3-proxy/server/utils/utils.go @@ -168,7 +168,9 @@ func TemplateExecution(tplPath, tplString string, logger log.Logger, rw http.Res func GetRequestURI(r *http.Request) string { scheme := "http" - if r.TLS != nil { + fwdScheme := r.Header.Get("X-Forwarded-Proto") + + if r.TLS != nil || fwdScheme == "https" { scheme = "https" } diff --git a/pkg/s3-proxy/server/utils/utils_test.go b/pkg/s3-proxy/server/utils/utils_test.go index 659f3520..69a5c094 100644 --- a/pkg/s3-proxy/server/utils/utils_test.go +++ b/pkg/s3-proxy/server/utils/utils_test.go @@ -939,6 +939,21 @@ func TestGetRequestURI(t *testing.T) { } } +func TestProxiedGetRequestURI(t *testing.T) { + req, err := http.NewRequest("GET", "http://localhost:989/fake/path", nil) + if err != nil { + t.Fatal(err) + } + // Add the same header a Load Balancer should set + req.Header.Set("X-Forwarded-Proto", "https") + + want := "https://localhost:989/fake/path" + got := GetRequestURI(req) + if got != want { + t.Errorf("GetRequestURI() = %v, want %v", got, want) + } +} + func Test_RequestHost(t *testing.T) { hXForwardedHost1 := http.Header{ "X-Forwarded-Host": []string{"fake.host"},