@@ -658,9 +658,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
658
658
if logger != nil {
659
659
switch v := logger .(type ) {
660
660
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 ) )
662
662
case Logger :
663
- v .Printf ("[DEBUG] %s %s" , req .Method , req .URL )
663
+ v .Printf ("[DEBUG] %s %s" , req .Method , redactURL ( req .URL ) )
664
664
}
665
665
}
666
666
@@ -715,9 +715,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
715
715
if err != nil {
716
716
switch v := logger .(type ) {
717
717
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 ) )
719
719
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 )
721
721
}
722
722
} else {
723
723
// Call this here to maintain the behavior of logging all requests,
@@ -753,7 +753,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
753
753
754
754
wait := c .Backoff (c .RetryWaitMin , c .RetryWaitMax , i , resp )
755
755
if logger != nil {
756
- desc := fmt .Sprintf ("%s %s" , req .Method , req .URL )
756
+ desc := fmt .Sprintf ("%s %s" , req .Method , redactURL ( req .URL ) )
757
757
if resp != nil {
758
758
desc = fmt .Sprintf ("%s (status: %d)" , desc , resp .StatusCode )
759
759
}
@@ -818,11 +818,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
818
818
// communicate why
819
819
if err == nil {
820
820
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 )
822
822
}
823
823
824
824
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 )
826
826
}
827
827
828
828
// Try to read the response body so we can reuse this connection.
@@ -903,3 +903,17 @@ func (c *Client) StandardClient() *http.Client {
903
903
Transport : & RoundTripper {Client : c },
904
904
}
905
905
}
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