Close body even if it got error http status.

Otherwise, http connections keep open if server
returned error status (e.g. Get returned error).
This commit is contained in:
Fumitoshi Ukai 2013-08-29 22:00:01 +09:00
parent 61c957aaf8
commit 38eed8b4ba

View File

@ -174,10 +174,10 @@ func (h *httpGetter) Get(context Context, in *pb.GetRequest, out *pb.GetResponse
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return fmt.Errorf("server returned: %v", res.Status)
}
defer res.Body.Close()
// TODO: avoid this garbage.
b, err := ioutil.ReadAll(res.Body)
if err != nil {