Skip to content
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

fix: Prevent unexpected warning from Resty when calling Client.SetDebug(false) #508

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (c *Client) R(ctx context.Context) *resty.Request {
func (c *Client) SetDebug(debug bool) *Client {
c.debug = debug
c.resty.SetDebug(debug)
// this ensures that if there is an Authorization header present, the value is sanitized/masked
c.sanitizeAuthorizationHeader()

return c
}
Expand Down Expand Up @@ -414,12 +412,14 @@ func (c *Client) SetHeader(name, value string) {
c.resty.SetHeader(name, value)
}

func (c *Client) sanitizeAuthorizationHeader() {
func (c *Client) enableLogSanitization() *Client {
c.resty.OnRequestLog(func(r *resty.RequestLog) error {
// masking authorization header
r.Header.Set("Authorization", "Bearer *******************************")
return nil
})

return c
}

// NewClient factory to create new Client struct
Expand Down Expand Up @@ -468,7 +468,8 @@ func NewClient(hc *http.Client) (client Client) {
SetRetryWaitTime(APISecondsPerPoll * time.Second).
SetPollDelay(APISecondsPerPoll * time.Second).
SetRetries().
SetDebug(envDebug)
SetDebug(envDebug).
enableLogSanitization()

return
}
Expand Down