Skip to content

Commit 2f0a224

Browse files
author
Anis Elleuch
committed
Address Harsha comments
1 parent 899540b commit 2f0a224

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

restapi/client-admin.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,13 @@ var httpClients = struct {
487487
m: make(map[string]*http.Client),
488488
}
489489

490+
func isLocalAddress(address string) bool {
491+
if u, err := url.Parse(address); err == nil && u.Host != "" {
492+
return address == "127.0.0.1" || strings.HasPrefix(address, "127.0.0.1:")
493+
}
494+
return false
495+
}
496+
490497
// GetConsoleHTTPClient caches different http clients depending on the target endpoint while taking
491498
// in consideration CA certs stored in ${HOME}/.console/certs/CAs and ${HOME}/.minio/certs/CAs
492499
// If the target endpoint points to a loopback device, skip the TLS verification.
@@ -502,9 +509,7 @@ func GetConsoleHTTPClient(address string) *http.Client {
502509
return client
503510
}
504511

505-
isLocalAddress := address == "127.0.0.1" || strings.HasPrefix(address, "127.0.0.1:")
506-
507-
client = PrepareConsoleHTTPClient(isLocalAddress)
512+
client = PrepareConsoleHTTPClient(isLocalAddress(address))
508513
httpClients.Lock()
509514
httpClients.m[address] = client
510515
httpClients.Unlock()

restapi/client.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24-
"net/url"
2524
"path"
2625
"strings"
2726
"time"
@@ -458,10 +457,7 @@ func newS3Config(endpoint, accessKey, secretKey, sessionToken string) *mc.Config
458457
s3Config.SessionToken = sessionToken
459458
s3Config.Signature = "S3v4"
460459

461-
insecure := false
462-
if u, err := url.ParseRequestURI(endpoint); err == nil && u.Host != "" {
463-
insecure = u.Host == "127.0.0.1" || strings.HasPrefix(u.Host, "127.0.0.1:")
464-
}
460+
insecure := isLocalAddress(endpoint)
465461
s3Config.Insecure = insecure
466462
s3Config.Transport = PrepareSTSClientTransport(insecure)
467463

0 commit comments

Comments
 (0)