From fc89165f9c69966dba8691893d7c07746fd965af Mon Sep 17 00:00:00 2001 From: "Jeevanandam M." Date: Wed, 18 Sep 2024 20:52:38 -0700 Subject: [PATCH] fix: do not parse response debug log with correct text (#858) --- request_test.go | 37 +++++++++++++++++++++++++++++++++++++ response.go | 3 +++ 2 files changed, 40 insertions(+) diff --git a/request_test.go b/request_test.go index f2209394..44bec455 100644 --- a/request_test.go +++ b/request_test.go @@ -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"` } diff --git a/response.go b/response.go index c3e4611b..f52b5c61 100644 --- a/response.go +++ b/response.go @@ -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))