Skip to content

Commit

Permalink
Merge pull request #42 from Teamwork/fix-parse-err
Browse files Browse the repository at this point in the history
Option to not log raw request body
  • Loading branch information
chrisjtwomey authored Mar 25, 2024
2 parents 18badb0 + b3239b0 commit 9042e54
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Options struct {
SkipQueryParams bool
SkipformParams bool
SkipRequestBody bool
// Option to not include raw request data with the log
SkipLogRawBody bool
}

// Audit entry.
Expand Down Expand Up @@ -214,8 +216,14 @@ func (a *Audit) filterFields(r *http.Request, opts Options) {
if bodyIsJSON && len(a.RequestBody) > 0 {
err := json.Unmarshal(a.RequestBody, &body)
if err != nil {
opts.Auditor.Log(r, errors.Wrapf(err, "could not parse body for %s %s: %s",
r.Method, r.URL.String(), stringutil.Left(string(a.RequestBody), 4000)))
msgFmt := "could not parse body for %s %s"
msgArgs := []interface{}{r.Method, r.URL.String()}

if !opts.SkipLogRawBody {
msgFmt += ": %s"
msgArgs = append(msgArgs, stringutil.Left(string(a.RequestBody), 4000))
}
opts.Auditor.Log(r, errors.Wrapf(err, msgFmt, msgArgs...))
}
}

Expand Down

0 comments on commit 9042e54

Please sign in to comment.