Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #101 from folbricht/http-body-close
Browse files Browse the repository at this point in the history
Close HTTP response body and empty it to avoid resource leaks and make use of keep-alive
  • Loading branch information
sclevine authored Mar 8, 2017
2 parents da6ce95 + 807bcd9 commit b933c81
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/internal/bus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (c *Client) makeRequest(url, method string, body []byte) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("request failed: %s", err)
}
defer response.Body.Close()

responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/internal/bus/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func openSession(url string, body io.Reader, httpClient *http.Client) (sessionID
if err != nil {
return "", err
}
defer response.Body.Close()

var sessionResponse struct{ SessionID string }
responseBody, err := ioutil.ReadAll(response.Body)
Expand Down
6 changes: 5 additions & 1 deletion api/internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func (s *Service) checkStatus() bool {
client := &http.Client{}
request, _ := http.NewRequest("GET", fmt.Sprintf("%s/status", s.url), nil)
response, err := client.Do(request)
if err == nil && response.StatusCode == 200 {
if err != nil {
return false
}
defer response.Body.Close()
if response.StatusCode == 200 {
return true
}
return false
Expand Down

0 comments on commit b933c81

Please sign in to comment.