Skip to content

Commit

Permalink
fix forwarded url, has to be earlier and constructed
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Mar 15, 2024
1 parent 351de86 commit e2ee5ba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,20 @@ func (h *Http) proxyHandler() http.HandlerFunc {
uu := ctx.Value(ctxURL).(*url.URL)
keepHost := ctx.Value(ctxKeepHost).(bool)
r.Header.Add("X-Forwarded-Host", r.Host)
scheme := "http"
if h.SSLConfig.SSLMode == SSLAuto || h.SSLConfig.SSLMode == SSLStatic {
h.setHeaderIfNotExists(r, "X-Forwarded-Proto", "https")
h.setHeaderIfNotExists(r, "X-Forwarded-Port", "443")
scheme = "https"
}
r.Header.Set("X-Forwarded-URL", fmt.Sprintf("%s://%s%s", scheme, r.Host, r.URL.String()))
r.URL.Path = uu.Path
r.URL.Host = uu.Host
r.URL.Scheme = uu.Scheme
log.Printf("[DEBUG] keep host is %t", keepHost)
if !keepHost {
r.Host = uu.Host
}
r.Header.Set("X-Forwarded-URL", r.URL.String())
h.setXRealIP(r)
},
Transport: &http.Transport{
Expand Down

0 comments on commit e2ee5ba

Please sign in to comment.