From 3bcb4a6ec66514a687a659ecf4cbb83e18d92069 Mon Sep 17 00:00:00 2001 From: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com> Date: Tue, 21 May 2024 12:13:42 -0400 Subject: [PATCH] fix: Prevent unexpected warning from Resty when calling Client.SetDebug(false) (#508) --- client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index bd730bc04..4c9eedb36 100644 --- a/client.go +++ b/client.go @@ -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 } @@ -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 @@ -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 }