From f9e7332d2ed6b9b8120a1b9fe403baaa537b0815 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Wed, 19 Jan 2022 23:42:37 +0100 Subject: [PATCH] Pass actual host arguments to downstream --- FinalCommander.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/FinalCommander.go b/FinalCommander.go index d492c62..fc50065 100644 --- a/FinalCommander.go +++ b/FinalCommander.go @@ -27,6 +27,8 @@ var contentServers []*content.Server var db *content.Database +var redirectListenAddress string + func selectNextContentServer(skip []int) *content.Server { inSkip := func(i int) bool { for _, c := range skip { @@ -80,6 +82,15 @@ func handle(ctx *httputils.RequestContext) { return } + host := ctx.GetRequestHeader("Host") + if host == "" && ctx.GetTLSServerName() != "" { + host = ctx.GetTLSServerName() + redirectListenAddress + } + + if host != "" { + host = "/" + host + } + if ctx.IsGet() || ctx.IsHead() { if debugOutput { log.Printf("Serve %s", ctx.GetPath()) @@ -170,7 +181,7 @@ func handle(ctx *httputils.RequestContext) { return } - ctx.DoRedirect(contentServer.GetContentURL(entry, privateKey, skip), http.StatusFound) + ctx.DoRedirect(contentServer.GetContentURL(entry, privateKey, skip)+host, http.StatusFound) } else { contentServer := selectNextContentServer(skip) if contentServer == nil { @@ -226,7 +237,7 @@ func handle(ctx *httputils.RequestContext) { } }() - ctx.DoRedirect(contentServer.GetHashURL(mh, privateKey, skip), http.StatusFound) + ctx.DoRedirect(contentServer.GetHashURL(mh, privateKey, skip)+host, http.StatusFound) } } else if ctx.IsOptions() { setOtherHeaders(ctx) @@ -366,5 +377,7 @@ func main() { Debug: debugOutput, } + redirectListenAddress = *listenAddress + server.Serve() }