diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-23 12:09:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-23 12:09:33 +0000 |
commit | b38fc20ae0e90d5b1c538a139aa0a7da1b7b5726 (patch) | |
tree | 3ce77cdb707b75c9d74c6ff2a8386dd06bd48b44 /workhorse/internal/api/api.go | |
parent | b3647b2a67930e8aa3c1b1dd9bda29c368c862ba (diff) | |
download | gitlab-ce-b38fc20ae0e90d5b1c538a139aa0a7da1b7b5726.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse/internal/api/api.go')
-rw-r--r-- | workhorse/internal/api/api.go | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/workhorse/internal/api/api.go b/workhorse/internal/api/api.go index a420288a95a..e434a847bf2 100644 --- a/workhorse/internal/api/api.go +++ b/workhorse/internal/api/api.go @@ -151,7 +151,7 @@ type Response struct { MaximumSize int64 } -// singleJoiningSlash is taken from reverseproxy.go:NewSingleHostReverseProxy +// singleJoiningSlash is taken from reverseproxy.go:singleJoiningSlash func singleJoiningSlash(a, b string) string { aslash := strings.HasSuffix(a, "/") bslash := strings.HasPrefix(b, "/") @@ -164,14 +164,36 @@ func singleJoiningSlash(a, b string) string { return a + b } +// joinURLPath is taken from reverseproxy.go:joinURLPath +func joinURLPath(a *url.URL, b string) (path string, rawpath string) { + if a.RawPath == "" && b == "" { + return singleJoiningSlash(a.Path, b), "" + } + + // Same as singleJoiningSlash, but uses EscapedPath to determine + // whether a slash should be added + apath := a.EscapedPath() + bpath := b + + aslash := strings.HasSuffix(apath, "/") + bslash := strings.HasPrefix(bpath, "/") + + switch { + case aslash && bslash: + return a.Path + bpath[1:], apath + bpath[1:] + case !aslash && !bslash: + return a.Path + "/" + bpath, apath + "/" + bpath + } + return a.Path + bpath, apath + bpath +} + // rebaseUrl is taken from reverseproxy.go:NewSingleHostReverseProxy func rebaseUrl(url *url.URL, onto *url.URL, suffix string) *url.URL { newUrl := *url newUrl.Scheme = onto.Scheme newUrl.Host = onto.Host - if suffix != "" { - newUrl.Path = singleJoiningSlash(url.Path, suffix) - } + newUrl.Path, newUrl.RawPath = joinURLPath(url, suffix) + if onto.RawQuery == "" || newUrl.RawQuery == "" { newUrl.RawQuery = onto.RawQuery + newUrl.RawQuery } else { |