Commit 96672c5e authored by Jacob Vosmaer's avatar Jacob Vosmaer

Set relative URL via -authBackend

parent af9e7622
...@@ -36,7 +36,6 @@ var listenUmask = flag.Int("listenUmask", 022, "Umask for Unix socket, default: ...@@ -36,7 +36,6 @@ var listenUmask = flag.Int("listenUmask", 022, "Umask for Unix socket, default:
var authBackend = flag.String("authBackend", "http://localhost:8080", "Authentication/authorization backend") var authBackend = flag.String("authBackend", "http://localhost:8080", "Authentication/authorization backend")
var authSocket = flag.String("authSocket", "", "Optional: Unix domain socket to dial authBackend at") var authSocket = flag.String("authSocket", "", "Optional: Unix domain socket to dial authBackend at")
var pprofListenAddr = flag.String("pprofListenAddr", "", "pprof listening address, e.g. 'localhost:6060'") var pprofListenAddr = flag.String("pprofListenAddr", "", "pprof listening address, e.g. 'localhost:6060'")
var relativeURLRoot = flag.String("relativeURLRoot", "/", "GitLab relative URL root")
var documentRoot = flag.String("documentRoot", "public", "Path to static files content") var documentRoot = flag.String("documentRoot", "public", "Path to static files content")
var responseHeadersTimeout = flag.Duration("proxyHeadersTimeout", time.Minute, "How long to wait for response headers when proxying the request") var responseHeadersTimeout = flag.Duration("proxyHeadersTimeout", time.Minute, "How long to wait for response headers when proxying the request")
var developmentMode = flag.Bool("developmentMode", false, "Allow to serve assets from Rails app") var developmentMode = flag.Bool("developmentMode", false, "Allow to serve assets from Rails app")
...@@ -170,6 +169,5 @@ func main() { ...@@ -170,6 +169,5 @@ func main() {
} }
upstream := newUpstream(*authBackend, proxyTransport) upstream := newUpstream(*authBackend, proxyTransport)
upstream.SetRelativeURLRoot(*relativeURLRoot)
log.Fatal(http.Serve(listener, upstream)) log.Fatal(http.Serve(listener, upstream))
} }
...@@ -68,25 +68,22 @@ func newUpstream(authBackend string, authTransport http.RoundTripper) *upstream ...@@ -68,25 +68,22 @@ func newUpstream(authBackend string, authTransport http.RoundTripper) *upstream
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
relativeURLRoot := u.Path
if !strings.HasSuffix(relativeURLRoot, "/") {
relativeURLRoot += "/"
}
u.Path = "" // Would cause redirect loop in ReverseProxy
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(u),
relativeURLRoot: "/", relativeURLRoot: relativeURLRoot,
} }
up.httpProxy.Transport = authTransport up.httpProxy.Transport = authTransport
return up return up
} }
func (u *upstream) SetRelativeURLRoot(relativeURLRoot string) {
u.relativeURLRoot = relativeURLRoot
if !strings.HasSuffix(u.relativeURLRoot, "/") {
u.relativeURLRoot += "/"
}
}
func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) { func (u *upstream) ServeHTTP(ow http.ResponseWriter, r *http.Request) {
var g httpRoute var g httpRoute
......
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