Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/term-0.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gururajsh authored Jul 10, 2024
2 parents 9c5cb73 + 52b12d9 commit 1beabb7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/win/windows-installer-v8-x64.iss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ AppName=Cloud Foundry CLI
AppVersion=VERSION
AppVerName=Cloud Foundry CLI version VERSION
AppPublisher=Cloud Foundry Foundation
ArchitecturesInstallIn64BitMode=x64 ia64
ArchitecturesAllowed=x64 ia64
ArchitecturesInstallIn64BitMode=x64compatible
ArchitecturesAllowed=x64compatible
PrivilegesRequired=none
DefaultDirName={pf}\Cloud Foundry
SetupIconFile=cf.ico
Expand Down
10 changes: 9 additions & 1 deletion api/cloudcontroller/ccv3/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccv3
import (
"io"
"net/http"
"strings"

"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
Expand Down Expand Up @@ -57,6 +58,7 @@ func (requester *RealRequester) newHTTPRequest(passedRequest requestOptions) (*c
}

request.Header = http.Header{}

if passedRequest.Header != nil {
request.Header = passedRequest.Header
}
Expand All @@ -69,9 +71,15 @@ func (requester *RealRequester) newHTTPRequest(passedRequest requestOptions) (*c
request.Header.Set("Accept", "application/json")
}

if request.Header.Get("Content-Type") == "" {
if !isDownloadDroplet(passedRequest.URL, passedRequest.RequestName) && request.Header.Get("Content-Type") == "" {
request.Header.Set("Content-Type", "application/json")
} else if isDownloadDroplet(passedRequest.URL, passedRequest.RequestName) && request.Header.Get("Content-Type") != "" {
request.Header.Del("Content-Type")
}

return cloudcontroller.NewRequest(request, passedRequest.Body), nil
}

func isDownloadDroplet(URL string, requestName string) bool {
return (strings.Contains(URL, "droplet") && strings.Contains(URL, "download")) || (requestName == internal.GetDropletBitsRequest)
}
28 changes: 28 additions & 0 deletions api/cloudcontroller/ccv3/requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,9 @@ var _ = Describe("shared request helpers", func() {
CombineHandlers(
VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/manifest"),
VerifyHeaderKV("Accept", "application/x-yaml"),
func(w http.ResponseWriter, req *http.Request) {
Expect(req.Header).To(HaveKey("Content-Type"), "Header Content-Type is not present")
},
RespondWith(
http.StatusOK,
expectedResponseBody,
Expand Down Expand Up @@ -1134,6 +1137,31 @@ var _ = Describe("shared request helpers", func() {
})
})
})

Context("Download a droplet", func() {
BeforeEach(func() {
requestName = internal.GetDropletBitsRequest
uriParams = internal.Params{"droplet_guid": "some-droplet-guid"}
})

When("The server returns an unauthorized error", func() {
BeforeEach(func() {
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodGet, "/v3/droplets/some-droplet-guid/download"),
func(w http.ResponseWriter, req *http.Request) {
Expect(req.Header).NotTo(HaveKey("Content-Type"), "Header Content-Type is present")
},
RespondWith(http.StatusUnauthorized, "", http.Header{}),
),
)
})

It("fails", func() {
Expect(executeErr).To(HaveOccurred())
})
})
})
})

Describe("MakeRequestSendRaw", func() {
Expand Down
1 change: 1 addition & 0 deletions cf/api/buildpack_bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (repo CloudControllerBuildpackBitsRepository) CreateBuildpackZipFile(buildp
if err != nil {
return nil, "", fmt.Errorf("%s: %s", T("Couldn't open buildpack file"), err.Error())
}
defer specifiedFile.Close()
err = normalizeBuildpackArchive(specifiedFile, zipFileToUpload)
if err != nil {
return nil, "", zipErrorHelper(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module code.cloudfoundry.org/cli

go 1.22
go 1.22.0

require (
code.cloudfoundry.org/bytefmt v0.0.0-20230612151507-41ef4d1f67a4
Expand Down

0 comments on commit 1beabb7

Please sign in to comment.