Skip to content

Commit

Permalink
Keep compiled regexp as global
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyist committed Jan 26, 2024
1 parent da61986 commit 33f0089
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions channel_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
// NilStatusCode is used when we have an error before even sending anything
const NilStatusCode int = 417

var sanitizeSecretsRegexp *regexp.Regexp

// NewChannelLog creates a new channel log for the passed in channel, id, and request and response info
func NewChannelLog(description string, channel Channel, msgID MsgID, method string, url string, statusCode int,
request string, response string, elapsed time.Duration, err error) *ChannelLog {
Expand Down Expand Up @@ -45,9 +47,11 @@ func sanitizeSecrets(body string) string {
pattern = "(?:Po-Api-Key:.+\\n|X-Api-Key:.+\\n|Authorization:.+\\n|Token:.+\\n)+"
}

re := regexp.MustCompile(pattern)
if sanitizeSecretsRegexp == nil {
sanitizeSecretsRegexp = regexp.MustCompile(pattern)
}

return re.ReplaceAllString(body, "")
return sanitizeSecretsRegexp.ReplaceAllString(body, "")
}

func sanitizeBody(body string) string {
Expand Down

0 comments on commit 33f0089

Please sign in to comment.