forked from aksdb/CalAnonSync
Fixed possible race condition
This commit is contained in:
parent
0c1c63e20e
commit
69aa8d81f6
|
@ -70,12 +70,9 @@ func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
r.SetBasicAuth(er.username, er.password)
|
||||
}
|
||||
|
||||
resp, err := er.delegate.RoundTrip(r)
|
||||
if err == nil && resp.StatusCode == http.StatusUnauthorized {
|
||||
er.initMutex.Lock()
|
||||
defer er.initMutex.Unlock()
|
||||
|
||||
if er.authType == authTypeUnknown {
|
||||
resp, err := er.delegate.RoundTrip(r)
|
||||
if err == nil && resp.StatusCode == http.StatusUnauthorized && er.authType == authTypeUnknown {
|
||||
// This is a good time to find out what the server prefers.
|
||||
authHeaders := resp.Header["Www-Authenticate"]
|
||||
if authHeaders != nil {
|
||||
|
@ -99,11 +96,12 @@ func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
Password: er.password,
|
||||
}
|
||||
}
|
||||
er.initMutex.Unlock()
|
||||
return er.RoundTrip(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
er.initMutex.Unlock()
|
||||
return resp, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue