Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
akrishna committed Mar 19, 2022
1 parent 08988a0 commit b21de20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 5 additions & 1 deletion conjure-go-client/httpclient/body_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package httpclient

import (
"bytes"
"github.com/palantir/conjure-go-runtime/v2/conjure-go-client/httpclient/internal"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -104,6 +105,9 @@ func (b *bodyMiddleware) readResponse(resp *http.Response, respErr error) error
if b.rawOutput && respErr == nil {
return nil
}
defer func() {
internal.DrainBody(resp)
}()

if respErr != nil {
return respErr
Expand All @@ -112,13 +116,13 @@ func (b *bodyMiddleware) readResponse(resp *http.Response, respErr error) error
// Verify we have a body to unmarshal. If the request was unsuccessful, the errorMiddleware will
// set a non-nil error and return no response.
if b.responseOutput == nil || resp == nil || resp.Body == nil || resp.ContentLength == 0 {
internal.DrainBody(resp)
return nil
}

decErr := b.responseDecoder.Decode(resp.Body, b.responseOutput)
if decErr != nil {
return decErr
}

return nil
}
5 changes: 0 additions & 5 deletions conjure-go-client/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ func (c *clientImpl) Do(ctx context.Context, params ...RequestParam) (*http.Resp
reqCopy := req.Clone(ctx)
resp, err = clientCopy.Do(reqCopy)
err = unwrapURLError(ctx, err)
// unless this is exactly the scenario where the caller has opted into being responsible for draining and closing
// the response body, be sure to do so here.
if !(err == nil && b.bodyMiddleware.rawOutput) {
internal.DrainBody(resp)
}
attempts++
if resp != nil && isSuccessfulOrBadRequest(resp.StatusCode) {
break
Expand Down

0 comments on commit b21de20

Please sign in to comment.