Skip to content

Commit

Permalink
Close body even if it got error http status.
Browse files Browse the repository at this point in the history
Otherwise, http connections keep open if server
returned error status (e.g. Get returned error).
  • Loading branch information
Fumitoshi Ukai committed Aug 29, 2013
1 parent 61c957a commit 38eed8b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 38eed8b

Please sign in to comment.