Protect http client cache with mutex

This commit is contained in:
Steve Streeting 2016-03-11 09:24:10 +00:00
parent 3329f1d49d
commit b6f74b66d5
2 changed files with 4 additions and 0 deletions

@ -46,6 +46,7 @@ type FetchPruneConfig struct {
type Configuration struct {
CurrentRemote string
httpClients map[string]*HttpClient
httpClientsMutex sync.Mutex
redirectingHttpClient *http.Client
ntlmSession ntlm.ClientSession
envVars map[string]string

@ -100,6 +100,9 @@ func (c *HttpClient) Do(req *http.Request) (*http.Response, error) {
// HttpClient returns a new HttpClient for the given host (which may be "host:port")
func (c *Configuration) HttpClient(host string) *HttpClient {
c.httpClientsMutex.Lock()
defer c.httpClientsMutex.Unlock()
if c.httpClients == nil {
c.httpClients = make(map[string]*HttpClient)
}