From 1373a6086ba14b8d09cd3797346272b5a6eb37cd Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 22 Oct 2015 14:03:25 -0400 Subject: [PATCH] Use cleanhttp for new http clients --- builtin/providers/aws/config.go | 6 +++--- builtin/providers/dme/config.go | 4 ++-- builtin/providers/packet/config.go | 5 ++--- state/remote/atlas.go | 8 +++++--- state/remote/etcd.go | 2 +- state/remote/http_test.go | 4 +++- state/remote/s3.go | 4 ++-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index dfd8b1b2ec..f8bb18589f 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -3,9 +3,9 @@ package aws import ( "fmt" "log" - "net/http" "strings" + "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-multierror" "github.com/aws/aws-sdk-go/aws" @@ -101,7 +101,7 @@ func (c *Config) Client() (interface{}, error) { Credentials: creds, Region: aws.String(c.Region), MaxRetries: aws.Int(c.MaxRetries), - HTTPClient: &http.Client{}, + HTTPClient: cleanhttp.DefaultClient(), } log.Println("[INFO] Initializing IAM Connection") @@ -127,7 +127,7 @@ func (c *Config) Client() (interface{}, error) { Credentials: creds, Region: aws.String("us-east-1"), MaxRetries: aws.Int(c.MaxRetries), - HTTPClient: &http.Client{}, + HTTPClient: cleanhttp.DefaultClient(), } log.Println("[INFO] Initializing DynamoDB connection") diff --git a/builtin/providers/dme/config.go b/builtin/providers/dme/config.go index 2d387673fe..cc75f120c1 100644 --- a/builtin/providers/dme/config.go +++ b/builtin/providers/dme/config.go @@ -3,8 +3,8 @@ package dme import ( "fmt" "log" - "net/http" + "github.com/hashicorp/go-cleanhttp" "github.com/soniah/dnsmadeeasy" ) @@ -22,7 +22,7 @@ func (c *Config) Client() (*dnsmadeeasy.Client, error) { return nil, fmt.Errorf("Error setting up client: %s", err) } - client.HTTP = &http.Client{} + client.HTTP = cleanhttp.DefaultClient() if c.UseSandbox { client.URL = dnsmadeeasy.SandboxURL diff --git a/builtin/providers/packet/config.go b/builtin/providers/packet/config.go index b7d408c626..bce54bf48c 100644 --- a/builtin/providers/packet/config.go +++ b/builtin/providers/packet/config.go @@ -1,8 +1,7 @@ package packet import ( - "net/http" - + "github.com/hashicorp/go-cleanhttp" "github.com/packethost/packngo" ) @@ -16,5 +15,5 @@ type Config struct { // Client() returns a new client for accessing packet. func (c *Config) Client() *packngo.Client { - return packngo.NewClient(consumerToken, c.AuthToken, &http.Client{}) + return packngo.NewClient(consumerToken, c.AuthToken, cleanhttp.DefaultClient()) } diff --git a/state/remote/atlas.go b/state/remote/atlas.go index 2c2c48895a..9a93730f38 100644 --- a/state/remote/atlas.go +++ b/state/remote/atlas.go @@ -11,6 +11,8 @@ import ( "os" "path" "strings" + + "github.com/hashicorp/go-cleanhttp" ) const ( @@ -83,7 +85,7 @@ func (c *AtlasClient) Get() (*Payload, error) { } // Request the url - client := &http.Client{} + client := cleanhttp.DefaultClient() resp, err := client.Do(req) if err != nil { return nil, err @@ -162,7 +164,7 @@ func (c *AtlasClient) Put(state []byte) error { req.ContentLength = int64(len(state)) // Make the request - client := &http.Client{} + client := cleanhttp.DefaultClient() resp, err := client.Do(req) if err != nil { return fmt.Errorf("Failed to upload state: %v", err) @@ -188,7 +190,7 @@ func (c *AtlasClient) Delete() error { } // Make the request - client := &http.Client{} + client := cleanhttp.DefaultClient() resp, err := client.Do(req) if err != nil { return fmt.Errorf("Failed to delete state: %v", err) diff --git a/state/remote/etcd.go b/state/remote/etcd.go index f596a8492c..7993603ff2 100644 --- a/state/remote/etcd.go +++ b/state/remote/etcd.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context" etcdapi "github.com/coreos/etcd/client" + "golang.org/x/net/context" ) func etcdFactory(conf map[string]string) (Client, error) { diff --git a/state/remote/http_test.go b/state/remote/http_test.go index 74ed1755a2..55d682d17d 100644 --- a/state/remote/http_test.go +++ b/state/remote/http_test.go @@ -8,6 +8,8 @@ import ( "net/http/httptest" "net/url" "testing" + + "github.com/hashicorp/go-cleanhttp" ) func TestHTTPClient_impl(t *testing.T) { @@ -24,7 +26,7 @@ func TestHTTPClient(t *testing.T) { t.Fatalf("err: %s", err) } - client := &HTTPClient{URL: url, Client: &http.Client{}} + client := &HTTPClient{URL: url, Client: cleanhttp.DefaultClient()} testClient(t, client) } diff --git a/state/remote/s3.go b/state/remote/s3.go index f6cfdfbde2..a8fefe6d17 100644 --- a/state/remote/s3.go +++ b/state/remote/s3.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "log" - "net/http" "os" "strconv" @@ -14,6 +13,7 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds" "github.com/aws/aws-sdk-go/service/s3" + "github.com/hashicorp/go-cleanhttp" ) func s3Factory(conf map[string]string) (Client, error) { @@ -76,7 +76,7 @@ func s3Factory(conf map[string]string) (Client, error) { awsConfig := &aws.Config{ Credentials: credentialsProvider, Region: aws.String(regionName), - HTTPClient: &http.Client{}, + HTTPClient: cleanhttp.DefaultClient(), } nativeClient := s3.New(awsConfig)