Skip to content

Commit

Permalink
Return response headers when both -f and -i flags are passed
Browse files Browse the repository at this point in the history
[#168151753]
  • Loading branch information
Marty Spiewak committed Sep 23, 2019
1 parent 2774725 commit a6d1ba3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions commands/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ func (c *CurlCommand) Execute([]string) error {
return err
}

if c.Fail && response.StatusCode >= 400 && response.StatusCode < 600 {
os.Exit(22)
}

if c.IncludeHeader {
headers := new(bytes.Buffer)
err = response.Header.Write(headers)
Expand All @@ -67,6 +63,10 @@ func (c *CurlCommand) Execute([]string) error {
fmt.Println(headers.String())
}

if c.Fail && response.StatusCode >= 400 && response.StatusCode < 600 {
os.Exit(22)
}

body, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
Expand Down
22 changes: 22 additions & 0 deletions commands/curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ var _ = Describe("Curl", func() {
Eventually(session).Should(Exit(22))
Eventually(session.Out.Contents()).Should(BeEmpty())
})
Context("when request includes -i flag", func() {
It("displays response headers to the user and exits with proper code", func() {
//language=json
responseJson := `
{
"error": "The request could not be completed because the credential does not exist or you do not have sufficient authorization."
}
`
server.RouteToHandler("GET", "/api/v1/data",
CombineHandlers(
VerifyRequest("GET", "/api/v1/data"),
VerifyForm(url.Values{"name": []string{"/doesNotExist"}}),
RespondWith(http.StatusNotFound, responseJson),
),
)

session := runCommand("curl", "-f", "-p", "api/v1/data?name=/doesNotExist", "-i")

Eventually(session).Should(Exit(22))
Eventually(session.Out).Should(Say("HTTP/1.1 404"))
})
})
})

It("the request continues to succeed", func() {
Expand Down

0 comments on commit a6d1ba3

Please sign in to comment.