Commit 985651fe authored by Jacob Vosmaer's avatar Jacob Vosmaer

Expand comment about redirect loop

parent 6d79151e
...@@ -64,20 +64,24 @@ type gitRequest struct { ...@@ -64,20 +64,24 @@ type gitRequest struct {
} }
func newUpstream(authBackend string, authTransport http.RoundTripper) *upstream { func newUpstream(authBackend string, authTransport http.RoundTripper) *upstream {
u, err := url.Parse(authBackend) gitlabURL, err := url.Parse(authBackend)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
relativeURLRoot := u.Path relativeURLRoot := gitlabURL.Path
if !strings.HasSuffix(relativeURLRoot, "/") { if !strings.HasSuffix(relativeURLRoot, "/") {
relativeURLRoot += "/" relativeURLRoot += "/"
} }
u.Path = "" // Would cause redirect loop in ReverseProxy
// If the relative URL is '/foobar' and we tell httputil.ReverseProxy to proxy
// to 'http://example.com/foobar' then we get a redirect loop, so we clear the
// Path field here.
gitlabURL.Path = ""
up := &upstream{ up := &upstream{
authBackend: authBackend, authBackend: authBackend,
httpClient: &http.Client{Transport: authTransport}, httpClient: &http.Client{Transport: authTransport},
httpProxy: httputil.NewSingleHostReverseProxy(u), httpProxy: httputil.NewSingleHostReverseProxy(gitlabURL),
relativeURLRoot: relativeURLRoot, relativeURLRoot: relativeURLRoot,
} }
up.httpProxy.Transport = authTransport up.httpProxy.Transport = authTransport
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment