Skip to content

Commit

Permalink
check response size for debug logs
Browse files Browse the repository at this point in the history
If response size exceeds 1000000, do not log response.
  • Loading branch information
sudo-suhas committed Oct 17, 2017
1 parent 9ac9c42 commit afc9b30
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ func (r *Response) RawBody() io.ReadCloser {
}

func (r *Response) fmtBodyString() string {
bodyStr := "***** NO CONTENT *****"
if r.body != nil {
if len(r.body) > 1000000 {
return "***** RESPONSE TOO LARGE *****"
}
ct := r.Header().Get(hdrContentTypeKey)
if IsJSONType(ct) {
out := acquireBuffer()
defer releaseBuffer(out)
if err := json.Indent(out, r.body, "", " "); err == nil {
bodyStr = string(out.Bytes())
err := json.Indent(out, r.body, "", " ")
if err == nil {
return out.String()
}
} else {
bodyStr = r.String()
return "unexpected error: " + err.Error()
}
return r.String()
}

return bodyStr
return "***** NO CONTENT *****"
}

0 comments on commit afc9b30

Please sign in to comment.