Pass actual host arguments to downstream
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-01-19 23:42:37 +01:00
parent e1d0e27c29
commit f9e7332d2e

View file

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