Ensure that cache file is closed after reading

This commit is contained in:
Mislav Marohnić 2020-10-01 19:18:11 +02:00
parent 93c8fc1e98
commit 1d435a3e2e

View file

@ -84,11 +84,13 @@ func readCache(ttl time.Duration, cacheFile string, req *http.Request) (*http.Re
}
res, err := http.ReadResponse(bufio.NewReader(f), req)
if res != nil {
if res == nil {
res.Body = &readCloser{
Reader: res.Body,
Closer: f,
}
} else {
f.Close()
}
return res, err
}