From f92094f2191c40c561559d0fa4b385210ce7e854 Mon Sep 17 00:00:00 2001 From: ccase Date: Mon, 6 Apr 2020 11:15:42 -0400 Subject: [PATCH] server: Replace string/parse trick for cloning with more efficient option. --- server/handlers.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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"