Skip to content

Commit

Permalink
Merge pull request cloudfoundry#222 from fraenkel/closeBody
Browse files Browse the repository at this point in the history
Close the response body
  • Loading branch information
Dan Lavine committed Jul 25, 2014
2 parents e2e5938 + 5f7da91 commit a835edf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
16 changes: 9 additions & 7 deletions cf/api/buildpack_bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"github.com/cloudfoundry/cli/cf/app_files"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/net"
"github.com/cloudfoundry/gofileutils/fileutils"
"io"
"mime/multipart"
"net/http"
"os"
"path"
"path/filepath"
"strings"

"github.com/cloudfoundry/cli/cf/app_files"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/net"
"github.com/cloudfoundry/gofileutils/fileutils"
)

type BuildpackBitsRepository interface {
Expand Down Expand Up @@ -199,6 +200,7 @@ func (repo CloudControllerBuildpackBitsRepository) downloadBuildpack(url string,
cb(nil, err)
return
}
defer response.Body.Close()

io.Copy(tempfile, response.Body)
tempfile.Seek(0, 0)
Expand Down
10 changes: 6 additions & 4 deletions cf/api/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package api
import (
"bufio"
"fmt"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/net"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/textproto"
"strings"

"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/net"
)

type CurlRepository interface {
Expand Down Expand Up @@ -52,6 +53,7 @@ func (repo CloudControllerCurlRepository) Request(method, path, headerString, bo
if err != nil {
return
}
defer res.Body.Close()

headerBytes, _ := httputil.DumpResponse(res, false)
resHeaders = string(headerBytes)
Expand Down
2 changes: 2 additions & 0 deletions cf/net/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (gateway Gateway) performRequestForResponseBytes(request *Request) (bytes [
if apiErr != nil {
return
}
defer rawResponse.Body.Close()

bytes, err := ioutil.ReadAll(rawResponse.Body)
if err != nil {
Expand Down Expand Up @@ -269,6 +270,7 @@ func (gateway Gateway) PerformPollingRequestForJSONResponse(request *Request, re
if apiErr != nil {
return
}
defer rawResponse.Body.Close()

if rawResponse.StatusCode > 203 || strings.TrimSpace(string(bytes)) == "" {
return
Expand Down

0 comments on commit a835edf

Please sign in to comment.