-
Notifications
You must be signed in to change notification settings - Fork 722
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
check response size for debug logs #99
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, "", " ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be better and concise. if err := json.Indent(out, r.body, "", " "); err == nil {
return out.String()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That results in a warning from golint - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually remove this line |
||
if err == nil { | ||
return out.String() | ||
} | ||
} else { | ||
bodyStr = r.String() | ||
return "unexpected error: " + err.Error() | ||
} | ||
return r.String() | ||
} | ||
|
||
return bodyStr | ||
return "***** NO CONTENT *****" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this
1000000
value? are you picking random max value to limit it? and why?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea.. It is arbitrary. What do you suggest? Should I add a
var
so that the user can override if required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this value configurable at client level would be best. Since some user wants to get complete body value.
debugBodySizeLimit int64
toClient
and method in the clientSetDebugBodyLimit(sl int64)
debugBodySizeLimit
default value asmath.MaxInt32
(this is good enough to begin with) at client instance creationThis way it will satisfy possibilities.