Fixed possible race condition

This commit is contained in:
Andreas Schneider 2018-04-03 11:55:45 +02:00
parent 0c1c63e20e
commit 69aa8d81f6
1 changed files with 23 additions and 25 deletions

View File

@ -70,12 +70,9 @@ func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
r.SetBasicAuth(er.username, er.password) r.SetBasicAuth(er.username, er.password)
} }
resp, err := er.delegate.RoundTrip(r)
if err == nil && resp.StatusCode == http.StatusUnauthorized {
er.initMutex.Lock() er.initMutex.Lock()
defer er.initMutex.Unlock() resp, err := er.delegate.RoundTrip(r)
if err == nil && resp.StatusCode == http.StatusUnauthorized && er.authType == authTypeUnknown {
if er.authType == authTypeUnknown {
// This is a good time to find out what the server prefers. // This is a good time to find out what the server prefers.
authHeaders := resp.Header["Www-Authenticate"] authHeaders := resp.Header["Www-Authenticate"]
if authHeaders != nil { if authHeaders != nil {
@ -99,11 +96,12 @@ func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
Password: er.password, Password: er.password,
} }
} }
er.initMutex.Unlock()
return er.RoundTrip(r) return er.RoundTrip(r)
} }
} }
}
er.initMutex.Unlock()
return resp, err return resp, err
} }