diff --git a/server/handlers.go b/server/handlers.go index 4f0af3d..04b0daf 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -544,8 +544,33 @@ func resolveWebAddress(r *http.Request, proxyPath string) string { return webAddress } +// Similar to the logic found here: +// https://github.com/golang/go/blob/release-branch.go1.14/src/net/http/clone.go#L22-L33 +func cloneURL(u *url.URL) *url.URL { + if u == nil { + return nil + } + + c := &url.URL{} + *c = *u + + if u.User != nil { + c.User = &url.Userinfo{} + *c.User = *u.User + } + + return c +} + func getURL(r *http.Request) *url.URL { - u, _ := url.Parse(r.URL.String()) + if r == nil || r.URL == nil { + return nil + } + + u := cloneURL(r.URL) + if u == nil { + return nil + } if r.TLS != nil { u.Scheme = "https"