Skip to content

Commit

Permalink
use defer to clean up error return
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Nov 28, 2022
1 parent c3c8997 commit f9e70a9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (t *Transport) save(res *http.Response) error {
}
chal, err := find(res.Header)
t.cacheMu.Lock()
defer t.cacheMu.Unlock()
if t.cache == nil {
t.cache = map[string]*cchal{}
}
Expand All @@ -72,14 +73,13 @@ func (t *Transport) save(res *http.Response) error {
// it and just matching the hostname. That being said, none of
// the major browsers respect the domain either.
host := res.Request.URL.Hostname()
if err == nil {
t.cache[host] = &cchal{c: chal}
} else {
if err != nil {
// if save is being invoked, the existing cached challenge didn't work
delete(t.cache, host)
return err
}
t.cacheMu.Unlock()
return err
t.cache[host] = &cchal{c: chal}
return nil
}

// digest creates credentials from the cached challenge
Expand Down

0 comments on commit f9e70a9

Please sign in to comment.