@@ -556,9 +556,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
556
556
if logger != nil {
557
557
switch v := logger .(type ) {
558
558
case LeveledLogger :
559
- v .Debug ("performing request" , "method" , req .Method , "url" , req .URL . Redacted ( ))
559
+ v .Debug ("performing request" , "method" , req .Method , "url" , redactURL ( req .URL ))
560
560
case Logger :
561
- v .Printf ("[DEBUG] %s %s" , req .Method , req .URL . Redacted ( ))
561
+ v .Printf ("[DEBUG] %s %s" , req .Method , redactURL ( req .URL ))
562
562
}
563
563
}
564
564
@@ -604,9 +604,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
604
604
if doErr != nil {
605
605
switch v := logger .(type ) {
606
606
case LeveledLogger :
607
- v .Error ("request failed" , "error" , doErr , "method" , req .Method , "url" , req .URL . Redacted ( ))
607
+ v .Error ("request failed" , "error" , doErr , "method" , req .Method , "url" , redactURL ( req .URL ))
608
608
case Logger :
609
- v .Printf ("[ERR] %s %s request failed: %v" , req .Method , req .URL . Redacted ( ), doErr )
609
+ v .Printf ("[ERR] %s %s request failed: %v" , req .Method , redactURL ( req .URL ), doErr )
610
610
}
611
611
} else {
612
612
// Call this here to maintain the behavior of logging all requests,
@@ -642,7 +642,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
642
642
643
643
wait := c .Backoff (c .RetryWaitMin , c .RetryWaitMax , i , resp )
644
644
if logger != nil {
645
- desc := fmt .Sprintf ("%s %s" , req .Method , req .URL . Redacted ( ))
645
+ desc := fmt .Sprintf ("%s %s" , req .Method , redactURL ( req .URL ))
646
646
if resp != nil {
647
647
desc = fmt .Sprintf ("%s (status: %d)" , desc , resp .StatusCode )
648
648
}
@@ -694,11 +694,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
694
694
// communicate why
695
695
if err == nil {
696
696
return nil , fmt .Errorf ("%s %s giving up after %d attempt(s)" ,
697
- req .Method , req .URL . Redacted ( ), attempt )
697
+ req .Method , redactURL ( req .URL ), attempt )
698
698
}
699
699
700
700
return nil , fmt .Errorf ("%s %s giving up after %d attempt(s): %w" ,
701
- req .Method , req .URL . Redacted ( ), attempt , err )
701
+ req .Method , redactURL ( req .URL ), attempt , err )
702
702
}
703
703
704
704
// Try to read the response body so we can reuse this connection.
@@ -779,3 +779,17 @@ func (c *Client) StandardClient() *http.Client {
779
779
Transport : & RoundTripper {Client : c },
780
780
}
781
781
}
782
+
783
+ // Taken from url.URL#Redacted() which was introduced in go 1.15.
784
+ // We can switch to using it directly if we'll bump the minimum required go version.
785
+ func redactURL (u * url.URL ) string {
786
+ if u == nil {
787
+ return ""
788
+ }
789
+
790
+ ru := * u
791
+ if _ , has := ru .User .Password (); has {
792
+ ru .User = url .UserPassword (ru .User .Username (), "xxxxx" )
793
+ }
794
+ return ru .String ()
795
+ }
0 commit comments