Skip to content

Commit

Permalink
Truncate debug output of HTTP responses if large
Browse files Browse the repository at this point in the history
  • Loading branch information
doozr committed Sep 23, 2016
1 parent a0cefa0 commit 9dba30b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions web/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ func (c client) Get(endPoint string, values url.Values) (response Response, err
if err != nil {
return
}
jot.Printf("web.client: GET %s received %s", url, string(bytes))
if jot.Enabled() {
o := string(bytes)
if len(o) > 256 {
o = o[:253] + "..."
}
jot.Printf("web.client: GET %s received %s", url, o)
}

respObj := apiResponse{}
err = json.Unmarshal(bytes, &respObj)
Expand Down Expand Up @@ -90,7 +96,13 @@ func (c client) Post(endPoint string, values url.Values) (response Response, err
if err != nil {
return
}
jot.Printf("web.client: POST to %s received %s", url, string(bytes))
if jot.Enabled() {
o := string(bytes)
if len(o) > 256 {
o = o[:253] + "..."
}
jot.Printf("web.client: POST %s received %s", url, o)
}

respObj := apiResponse{}
err = json.Unmarshal(bytes, &respObj)
Expand Down

0 comments on commit 9dba30b

Please sign in to comment.