@@ -658,9 +658,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
658658 if logger != nil {
659659 switch v := logger .(type ) {
660660 case LeveledLogger :
661- v .Debug ("performing request" , "method" , req .Method , "url" , req .URL )
661+ v .Debug ("performing request" , "method" , req .Method , "url" , redactURL ( req .URL ) )
662662 case Logger :
663- v .Printf ("[DEBUG] %s %s" , req .Method , req .URL )
663+ v .Printf ("[DEBUG] %s %s" , req .Method , redactURL ( req .URL ) )
664664 }
665665 }
666666
@@ -715,9 +715,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
715715 if err != nil {
716716 switch v := logger .(type ) {
717717 case LeveledLogger :
718- v .Error ("request failed" , "error" , err , "method" , req .Method , "url" , req .URL )
718+ v .Error ("request failed" , "error" , err , "method" , req .Method , "url" , redactURL ( req .URL ) )
719719 case Logger :
720- v .Printf ("[ERR] %s %s request failed: %v" , req .Method , req .URL , err )
720+ v .Printf ("[ERR] %s %s request failed: %v" , req .Method , redactURL ( req .URL ) , err )
721721 }
722722 } else {
723723 // Call this here to maintain the behavior of logging all requests,
@@ -753,7 +753,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
753753
754754 wait := c .Backoff (c .RetryWaitMin , c .RetryWaitMax , i , resp )
755755 if logger != nil {
756- desc := fmt .Sprintf ("%s %s" , req .Method , req .URL )
756+ desc := fmt .Sprintf ("%s %s" , req .Method , redactURL ( req .URL ) )
757757 if resp != nil {
758758 desc = fmt .Sprintf ("%s (status: %d)" , desc , resp .StatusCode )
759759 }
@@ -818,11 +818,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
818818 // communicate why
819819 if err == nil {
820820 return nil , fmt .Errorf ("%s %s giving up after %d attempt(s)" ,
821- req .Method , req .URL , attempt )
821+ req .Method , redactURL ( req .URL ) , attempt )
822822 }
823823
824824 return nil , fmt .Errorf ("%s %s giving up after %d attempt(s): %w" ,
825- req .Method , req .URL , attempt , err )
825+ req .Method , redactURL ( req .URL ) , attempt , err )
826826}
827827
828828// Try to read the response body so we can reuse this connection.
@@ -903,3 +903,17 @@ func (c *Client) StandardClient() *http.Client {
903903 Transport : & RoundTripper {Client : c },
904904 }
905905}
906+
907+ // Taken from url.URL#Redacted() which was introduced in go 1.15.
908+ // We can switch to using it directly if we'll bump the minimum required go version.
909+ func redactURL (u * url.URL ) string {
910+ if u == nil {
911+ return ""
912+ }
913+
914+ ru := * u
915+ if _ , has := ru .User .Password (); has {
916+ ru .User = url .UserPassword (ru .User .Username (), "xxxxx" )
917+ }
918+ return ru .String ()
919+ }
0 commit comments