Skip to content

Commit

Permalink
fix: do not parse response debug log with correct text (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 19, 2024
1 parent 321cab9 commit fc89165
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,43 @@ func TestRequestDoNotParseResponse(t *testing.T) {
assertNil(t, resp.RawBody())
}

func TestRequestDoNotParseResponseDebugLog(t *testing.T) {
ts := createGetServer(t)
defer ts.Close()

t.Run("do not parse response debug log client level", func(t *testing.T) {
c := dc().
SetDoNotParseResponse(true).
SetDebug(true)

var lgr bytes.Buffer
c.outputLogTo(&lgr)

_, err := c.R().
SetQueryParam("request_no", strconv.FormatInt(time.Now().Unix(), 10)).
Get(ts.URL + "/")

assertError(t, err)
assertEqual(t, true, strings.Contains(lgr.String(), "***** DO NOT PARSE RESPONSE - Enabled *****"))
})

t.Run("do not parse response debug log request level", func(t *testing.T) {
c := dc()

var lgr bytes.Buffer
c.outputLogTo(&lgr)

_, err := c.R().
SetDebug(true).
SetDoNotParseResponse(true).
SetQueryParam("request_no", strconv.FormatInt(time.Now().Unix(), 10)).
Get(ts.URL + "/")

assertError(t, err)
assertEqual(t, true, strings.Contains(lgr.String(), "***** DO NOT PARSE RESPONSE - Enabled *****"))
})
}

type noCtTest struct {
Response string `json:"response"`
}
Expand Down
3 changes: 3 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func (r *Response) setReceivedAt() {
}

func (r *Response) fmtBodyString(sl int64) string {
if r.Request.client.notParseResponse || r.Request.notParseResponse {
return "***** DO NOT PARSE RESPONSE - Enabled *****"
}
if len(r.body) > 0 {
if int64(len(r.body)) > sl {
return fmt.Sprintf("***** RESPONSE TOO LARGE (size - %d) *****", len(r.body))
Expand Down

0 comments on commit fc89165

Please sign in to comment.