Skip to content

Commit fc89165

Browse files
authored
fix: do not parse response debug log with correct text (#858)
1 parent 321cab9 commit fc89165

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

request_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,43 @@ func TestRequestDoNotParseResponse(t *testing.T) {
17101710
assertNil(t, resp.RawBody())
17111711
}
17121712

1713+
func TestRequestDoNotParseResponseDebugLog(t *testing.T) {
1714+
ts := createGetServer(t)
1715+
defer ts.Close()
1716+
1717+
t.Run("do not parse response debug log client level", func(t *testing.T) {
1718+
c := dc().
1719+
SetDoNotParseResponse(true).
1720+
SetDebug(true)
1721+
1722+
var lgr bytes.Buffer
1723+
c.outputLogTo(&lgr)
1724+
1725+
_, err := c.R().
1726+
SetQueryParam("request_no", strconv.FormatInt(time.Now().Unix(), 10)).
1727+
Get(ts.URL + "/")
1728+
1729+
assertError(t, err)
1730+
assertEqual(t, true, strings.Contains(lgr.String(), "***** DO NOT PARSE RESPONSE - Enabled *****"))
1731+
})
1732+
1733+
t.Run("do not parse response debug log request level", func(t *testing.T) {
1734+
c := dc()
1735+
1736+
var lgr bytes.Buffer
1737+
c.outputLogTo(&lgr)
1738+
1739+
_, err := c.R().
1740+
SetDebug(true).
1741+
SetDoNotParseResponse(true).
1742+
SetQueryParam("request_no", strconv.FormatInt(time.Now().Unix(), 10)).
1743+
Get(ts.URL + "/")
1744+
1745+
assertError(t, err)
1746+
assertEqual(t, true, strings.Contains(lgr.String(), "***** DO NOT PARSE RESPONSE - Enabled *****"))
1747+
})
1748+
}
1749+
17131750
type noCtTest struct {
17141751
Response string `json:"response"`
17151752
}

response.go

+3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ func (r *Response) setReceivedAt() {
171171
}
172172

173173
func (r *Response) fmtBodyString(sl int64) string {
174+
if r.Request.client.notParseResponse || r.Request.notParseResponse {
175+
return "***** DO NOT PARSE RESPONSE - Enabled *****"
176+
}
174177
if len(r.body) > 0 {
175178
if int64(len(r.body)) > sl {
176179
return fmt.Sprintf("***** RESPONSE TOO LARGE (size - %d) *****", len(r.body))

0 commit comments

Comments
 (0)