Skip to content

Commit

Permalink
Fix: cache clientIP in GetConsoleHTTPClient (minio#3056)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangitvitz authored and cesnietor committed Jan 12, 2024
1 parent 8bcff1b commit 31289bf
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions restapi/client-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"net/http"
"net/url"
"strings"
"sync"
"time"

"github.com/minio/console/pkg/utils"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 31289bf

Please sign in to comment.