Fix: cache clientIP in GetConsoleHTTPClient (#3056)
This commit is contained in:
@@ -25,7 +25,6 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/minio/console/pkg/utils"
|
||||
@@ -482,15 +481,6 @@ func newAdminFromCreds(accessKey, secretKey, endpoint string, tlsEnabled bool) (
|
||||
return minioClient, nil
|
||||
}
|
||||
|
||||
// httpClient is a custom http client, this client should not be called directly and instead be
|
||||
// called using GetConsoleHTTPClient() to ensure is initialized and the certificates are loaded correctly
|
||||
var httpClients = struct {
|
||||
sync.Mutex
|
||||
m map[string]*http.Client
|
||||
}{
|
||||
m: make(map[string]*http.Client),
|
||||
}
|
||||
|
||||
// isLocalAddress returns true if the url contains an IPv4/IPv6 hostname
|
||||
// that points to the local machine - FQDN are not supported
|
||||
func isLocalIPEndpoint(addr string) bool {
|
||||
@@ -520,17 +510,8 @@ func GetConsoleHTTPClient(address string, clientIP string) *http.Client {
|
||||
address = u.Hostname()
|
||||
}
|
||||
|
||||
httpClients.Lock()
|
||||
client, ok := httpClients.m[address]
|
||||
httpClients.Unlock()
|
||||
if ok {
|
||||
return client
|
||||
}
|
||||
client := PrepareConsoleHTTPClient(isLocalIPAddress(address), clientIP)
|
||||
|
||||
client = PrepareConsoleHTTPClient(isLocalIPAddress(address), clientIP)
|
||||
httpClients.Lock()
|
||||
httpClients.m[address] = client
|
||||
httpClients.Unlock()
|
||||
return client
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user