From ba2230b5ce47bd2d7c0eca61d648135904f41eb7 Mon Sep 17 00:00:00 2001 From: Wojtek Bednarzak Date: Wed, 12 Dec 2018 10:51:50 +0000 Subject: [PATCH] Add DefaultConfigWithClient which allows to specify custom http clients. There is no functionality change for existing clients. --- api/api.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/api.go b/api/api.go index 1ea032ae5c3..96b0e1b5beb 100644 --- a/api/api.go +++ b/api/api.go @@ -15,7 +15,7 @@ import ( "strings" "time" - "github.com/hashicorp/go-cleanhttp" + cleanhttp "github.com/hashicorp/go-cleanhttp" rootcerts "github.com/hashicorp/go-rootcerts" ) @@ -199,9 +199,15 @@ func (t *TLSConfig) Copy() *TLSConfig { // DefaultConfig returns a default configuration for the client func DefaultConfig() *Config { + return DefaultConfigWithClient(cleanhttp.DefaultClient()) +} + +// DefaultConfigWithClient uses the default configuration but with an addition +// of being able to specify your own http client for connections. +func DefaultConfigWithClient(client *http.Client) *Config { config := &Config{ Address: "http://127.0.0.1:4646", - httpClient: cleanhttp.DefaultClient(), + httpClient: client, TLSConfig: &TLSConfig{}, } transport := config.httpClient.Transport.(*http.Transport)