From d554eb8e2d006562f1e403b02795e1367daf658e Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Wed, 6 Jan 2021 13:33:46 +0100 Subject: [PATCH] clone url --- server/handlers.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/handlers.go b/server/handlers.go index a03e511..5c61a8a 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -556,8 +556,22 @@ func resolveWebAddress(r *http.Request, proxyPath string, proxyPort string) stri 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 { + c := &url.URL{} + *c = *u + + if u.User != nil { + c.User = &url.Userinfo{} + *c.User = *u.User + } + + return c +} + func getURL(r *http.Request, proxyPort string) *url.URL { - u, _ := url.Parse(r.URL.String()) + u := cloneURL(r.URL) if r.TLS != nil { u.Scheme = "https"