From: Sergey Matveev Date: Wed, 8 Sep 2021 19:39:02 +0000 (+0300) Subject: Set BasicAuth before request X-Git-Tag: v0.1.0~71 X-Git-Url: http://www.git.stargrave.org/?p=tofuproxy.git;a=commitdiff_plain;h=2a793fabff3fefc42e99a43a7a26eee2fb98badf Set BasicAuth before request --- diff --git a/trip.go b/trip.go index fa34445..a2e2565 100644 --- a/trip.go +++ b/trip.go @@ -73,6 +73,14 @@ func roundTrip(w http.ResponseWriter, req *http.Request) { reqFlags := []string{} unauthorized := false + + authCacheM.Lock() + if creds, ok := authCache[req.URL.Host]; ok { + req.SetBasicAuth(creds[0], creds[1]) + unauthorized = true + } + authCacheM.Unlock() + Retry: resp, err := transport.RoundTrip(req) if err != nil { @@ -88,11 +96,6 @@ Retry: delete(authCache, req.URL.Host) } else { unauthorized = true - if creds, ok := authCache[req.URL.Host]; ok { - authCacheM.Unlock() - req.SetBasicAuth(creds[0], creds[1]) - goto Retry - } } fifos.SinkOther <- fmt.Sprintf("%s\tauthorization required", req.URL.Host) user, pass, err := authDialog(host, resp.Header.Get("WWW-Authenticate"))