Makes the insecure transport work like the default one.

This commit is contained in:
James Phillips 2015-12-17 06:42:07 -08:00
parent d57e60a123
commit f6546a0e46
1 changed files with 18 additions and 4 deletions

View File

@ -123,13 +123,21 @@ type Config struct {
Token string Token string
} }
// defaultHttpClient is a shared client instance that is used to prevent apps
// that create multiple clients from opening multiple connections, which would
// leak file descriptors.
var defaultHttpClient = cleanhttp.DefaultClient() var defaultHttpClient = cleanhttp.DefaultClient()
var defaultInsecureTransport = &http.Transport{ // defaultInsecureTransport is a shared transport that will get injected into
TLSClientConfig: &tls.Config{ // the defaultHttpClient if the CONSUL_HTTP_SSL_VERIFY environment variable is
// set to true.
var defaultInsecureTransport = func() *http.Transport {
trans := cleanhttp.DefaultTransport()
trans.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
},
} }
return trans
}()
// DefaultConfig returns a default configuration for the client // DefaultConfig returns a default configuration for the client
func DefaultConfig() *Config { func DefaultConfig() *Config {
@ -193,7 +201,13 @@ type Client struct {
config Config config Config
} }
// unixClients contains a set of shared UNIX socket clients, indexed by address.
// These shared instances are used to prevent apps that create multiple clients
// from opening multiple connections, which would leak file descriptors.
var unixClients = make(map[string]*http.Client) var unixClients = make(map[string]*http.Client)
// unixClientsLock serializes access to the unixClients map, since most users
// would expect NewClient to be thread-safe.
var unixClientsLock sync.Mutex var unixClientsLock sync.Mutex
// NewClient returns a new client // NewClient returns a new client