Skip to content

Commit

Permalink
feat: do not escape HTML in the debug log when jsonEscapeHTML set to …
Browse files Browse the repository at this point in the history
…false, inspired by pr #544

Signed-off-by: Jeevanandam M <jeeva@myjeeva.com>
  • Loading branch information
jeevatkm committed Mar 19, 2023
1 parent 3a4e389 commit f49b62e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion request.go
Expand Up @@ -930,7 +930,7 @@ func (r *Request) fmtBodyString(sl int64) (body string) {
contentType := r.Header.Get(hdrContentTypeKey)
kind := kindOf(r.Body)
if canJSONMarshal(contentType, kind) {
prtBodyBytes, err = json.MarshalIndent(&r.Body, "", " ")
prtBodyBytes, err = noescapeJSONMarshalIndent(&r.Body)
} else if IsXMLType(contentType) && (kind == reflect.Struct) {
prtBodyBytes, err = xml.MarshalIndent(&r.Body, "", " ")
} else if b, ok := r.Body.(string); ok {
Expand Down Expand Up @@ -992,3 +992,18 @@ var noescapeJSONMarshal = func(v interface{}) (*bytes.Buffer, error) {

return buf, nil
}

var noescapeJSONMarshalIndent = func(v interface{}) ([]byte, error) {
buf := acquireBuffer()
defer releaseBuffer(buf)

encoder := json.NewEncoder(buf)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")

if err := encoder.Encode(v); err != nil {
return nil, err
}

return buf.Bytes(), nil
}

0 comments on commit f49b62e

Please sign in to comment.