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() }