Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not parse response debug log with correct text #858

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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