Use authentification credentials from proxy's configuration as a default. (#951)

This commit is contained in:
Viacheslav Chimishuk
2016-07-22 20:33:50 +03:00
committed by Matt Holt
parent 6490ff6224
commit 62e8c4b76b
2 changed files with 73 additions and 0 deletions
+6
View File
@@ -110,6 +110,12 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
if proxy == nil {
proxy = NewSingleHostReverseProxy(nameURL, host.WithoutPathPrefix)
}
// use upstream credentials by default
if outreq.Header.Get("Authorization") == "" && nameURL.User != nil {
pwd, _ := nameURL.User.Password()
outreq.SetBasicAuth(nameURL.User.Username(), pwd)
}
} else {
outreq.Host = host.Name
}